@ 2015-07-11T22:24:43Z <?php
class Placeholder{}
function curry(callable $func, ... $curriedArgs) {
return function(...$fulfillment) use ($func, $curriedArgs) {
return $func(...array_merge(array_map(function($arg) use ($fulfillment) {
if ($arg instanceof Placeholder)
return array_shift($fulfillment);
return $arg;
}, $curriedArgs), $fulfillment));
};
};
$resultset = json_decode('[{
"id": 1,
"gender": "Male",
"name": "Matthew"
}, {
"id": 2,
"gender": "Male",
"name": "Willie"
}, {
"id": 3,
"gender": "Female",
"name": "Ann"
}, {
"id": 4,
"gender": "Female",
"name": "Margaret"
}, {
"id": 5,
"gender": "Female",
"name": "Marie"
}]',TRUE);
$filterGender = function($row,$gender){
return $row['gender']==$gender;
};
$detectMen = curry($filterGender,(new Placeholder),'Male');
$detectWomen = curry($filterGender,(new Placeholder),'Female');
var_dump($detectMen(['gender'=>'Male'])); //works
$getLadies = curry('array_filter',(new Placeholder),$detectWomen);
var_dump($getLadies($resultset)); //does not work
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.25 , 8.3.0 - 8.3.13 bool(true)
Fatal error: Uncaught TypeError: array_filter(): Argument #3 ($mode) must be of type int, array given in /in/0i5FV:5
Stack trace:
#0 /in/0i5FV(5): array_filter(Array, Object(Closure), Array)
#1 /in/0i5FV(46): {closure}(Array)
#2 {main}
thrown in /in/0i5FV on line 5
Process exited with code 255 . Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.30 bool(true)
Fatal error: Uncaught TypeError: array_filter(): Argument #3 ($mode) must be of type int, array given in /in/0i5FV:9
Stack trace:
#0 /in/0i5FV(9): array_filter(Array, Object(Closure), Array)
#1 /in/0i5FV(46): {closure}(Array)
#2 {main}
thrown in /in/0i5FV on line 9
Process exited with code 255 . Output for 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 bool(true)
Warning: array_filter() expects parameter 3 to be int, array given in /in/0i5FV on line 9
NULL
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.6 - 7.2.33 bool(true)
Warning: array_filter() expects parameter 3 to be integer, array given in /in/0i5FV on line 9
NULL
Output for 5.6.7 - 5.6.28 bool(true)
Warning: array_filter() expects parameter 3 to be long, array given in /in/0i5FV on line 9
NULL
Output for 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/0i5FV on line 3
Process exited with code 255 . Output for 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/0i5FV on line 3
Process exited with code 255 . Output for 5.0.0 - 5.0.5 Parse error: parse error, unexpected '.', expecting '&' or T_VARIABLE in /in/0i5FV on line 3
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/0i5FV on line 3
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/0i5FV on line 3
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `')'' in /in/0i5FV on line 3
Process exited with code 255 . preferences:dark mode live preview
75.98 ms | 420 KiB | 5 Q