Function composition: Difference between revisions

(→‎{{header|Perl 6}}: show that ring operator is composable)
Line 976:
 
=={{header|PHP}}==
<lang php>function compose($f, $g) {<?php
function compose($f, $g) {
return create_function('$x', "return $f($g(\$x));");
}
 
$trim_strlen = compose('strlen', 'trim');
echo $result = $trim_strlen(' Test '), "\n"; // prints 4</lang>
?></lang>
{{works with|PHP|5.3+}}
<lang php><?php
function compose($f, $g) {
return function($x) use ($f, $g) { return $f($g($x)); };
}
 
$trim_strlen = compose(strlen, trim);
echo $result = $trim_strlen(' Test '), "\n"; // prints 4
?></lang>
 
=={{header|PicoLisp}}==
Anonymous user