Created
August 1, 2009 11:08
-
-
Save anonymous/159639 to your computer and use it in GitHub Desktop.
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
<?php | |
function lambda() { | |
if(func_num_args() > 1) { | |
$func = func_get_arg(1); | |
if($func[strlen($func)-1] != ';') | |
$func = $func.';'; | |
return create_function(func_get_arg(0), 'return '.$func); | |
} else { | |
$func = func_get_arg(0); | |
if($func[strlen($func)-1] != ';') | |
$func = $func.';'; | |
return create_function('', 'return '.$func); | |
} | |
} | |
function map($param,$func,$arg) { | |
return array_map(lambda($param, $func),$arg); | |
} | |
//'each' is taken by some dumb function | |
function every($func,$arg) { | |
$array = array(); | |
foreach($arg as $a) { | |
$array[] = $a; | |
call_user_func($func,$a); | |
} | |
return $array; | |
} | |
function select($expr,$arg) { | |
return array_filter( | |
$arg, | |
lambda('$_', $expr) | |
); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment