We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 08ef1e5 commit 375b35bCopy full SHA for 375b35b
src/Type/Collection.php
@@ -4,6 +4,7 @@
4
5
namespace Constructo\Type;
6
7
+use Closure;
8
use Constructo\Contract\Collectable;
9
use Constructo\Contract\Exportable;
10
use Constructo\Support\Datum;
@@ -37,6 +38,20 @@ final public function push(object $datum): void
37
38
$this->data[] = $this->validate($datum);
39
}
40
41
+ /**
42
+ * @return T|null
43
+ */
44
+ public function find(Closure $closure): mixed
45
+ {
46
+ foreach ($this->data as $datum) {
47
+ $matches = $closure($datum);
48
+ if ($matches === true) {
49
+ return $datum;
50
+ }
51
52
+ return null;
53
54
+
55
abstract protected function validate(mixed $datum): mixed;
56
57
protected function exception(string $type, mixed $datum): DomainException
0 commit comments