Skip to content

Commit

Permalink
feat: wrap iterable search with Option
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Apr 18, 2024
1 parent d211454 commit 0e29740
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Psl/Iter/first.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -16,8 +19,8 @@
function first(iterable $iterable)
{
foreach ($iterable as $v) {
return $v;
return Option::some($v);
}

return null;
return Option::none();
}

0 comments on commit 0e29740

Please sign in to comment.