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