From 0e29740c937ce7530132b9e895f445400fe11cc0 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 18 Apr 2024 15:32:19 +0200 Subject: [PATCH] feat: wrap iterable search with Option --- src/Psl/Iter/first.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Psl/Iter/first.php b/src/Psl/Iter/first.php index cc14e94f..c9c577a1 100644 --- a/src/Psl/Iter/first.php +++ b/src/Psl/Iter/first.php @@ -4,8 +4,11 @@ namespace Psl\Iter; +use Psl\Option\Option; + /** - * Returns the first element of an iterable, if the iterable is empty, null will be returned. + * Returns the first element of an iterable wrapped int {@see Option::some}, + * if the iterable is empty, {@see Option::none} will be returned. * * @template T * @@ -16,8 +19,8 @@ function first(iterable $iterable) { foreach ($iterable as $v) { - return $v; + return Option::some($v); } - return null; + return Option::none(); }