Skip to content

Instantly share code, notes, and snippets.

@clairvy
Created December 8, 2009 08:28
Show Gist options
  • Save clairvy/251521 to your computer and use it in GitHub Desktop.
Save clairvy/251521 to your computer and use it in GitHub Desktop.
<?php
function fix($f) {
return function($x) use ($f) {
return $f(fix($f), $x);
};
};
$map = function($f, $xs) {
$func = fix(function($sf, $ys) use ($f) {
if (count($ys) > 0) {
$y = array_shift($ys);
$a = $sf($ys);
array_unshift($a, $f($y));
return $a;
} else {
return array();
}
});
return $func($xs);
};
$double = function($x) {return $x * 2;};
print_r($map($double, array(1,2,3)));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment