Created
April 9, 2021 15:57
-
-
Save auxiliaire/5dcfda0ec6b716a1478641e6ce1059fc to your computer and use it in GitHub Desktop.
The `maybe` function in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function maybe(...$args) { | |
| return curry(fn(mixed $v, callable $f, Maybe $m) => | |
| match (true) { | |
| $m->isNothing() => $v, | |
| default => call_user_func($f, $m->get()) | |
| } | |
| )(...$args); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment