Last active
October 3, 2015 19:37
-
-
Save slifin/2c865d5abf21e4e6b2eb to your computer and use it in GitHub Desktop.
currying so far
This file contains 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
class Placeholder{} | |
function curry(callable $fn,...$start) { | |
return function (...$args) use ($fn, $start){ | |
$apply = array_merge($start,$args); | |
$apply = array_map(function($v) use(&$args){ | |
if ($v instanceof Placeholder) | |
return array_shift($args); | |
return $v; | |
},$apply); | |
return $fn(...$apply); | |
}; | |
} | |
function compose(...$fns) { | |
$prev = array_shift($fns); | |
foreach ($fns as $fn){ | |
$prev = function(...$args) use ($fn, $prev) { | |
return $prev($fn(...$args)); | |
}; | |
} | |
return $prev; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment