Add tap for Option and Result
This commit is contained in:
@@ -202,4 +202,17 @@ readonly class Option
|
||||
{
|
||||
return self::isSome($it) ? $it->get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tap into the `Result` for a secondary action, returning the result
|
||||
*
|
||||
* @param callable(Option<T>): mixed $f The function to run (return value is ignored)
|
||||
* @param Option<T> $it The option against which the function should be run
|
||||
* @return Option<T> The same option provided
|
||||
*/
|
||||
public static function tap(callable $f, Option $it): Option
|
||||
{
|
||||
$f($it);
|
||||
return $it;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user