Skip to content

Instantly share code, notes, and snippets.

@auxiliaire
Created April 21, 2022 19:36
Show Gist options
  • Select an option

  • Save auxiliaire/a881794e0517bbcab7f1cfe3b2f724ea to your computer and use it in GitHub Desktop.

Select an option

Save auxiliaire/a881794e0517bbcab7f1cfe3b2f724ea to your computer and use it in GitHub Desktop.
The `either` function in PHP
function either(...$args) {
return self::curry(function(callable $f, callable $g, Either $e) {
return match (true) {
$e->isLeft() => $f($e->value),
default => $g($e->value)
};
})(...$args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment