}, 'arity1' => function () { return arity(function ($a, $b) { }) !== 2; }, 'arity2' => function ($n) { return arity(nary(function () { }, $n % 100)) !== $n % 100; }, 'arity3' => function () { return arity('plus') !== 2; }, 'arity4' => function () { return arity(plus(2)) !== 1; }, 'arity5' => function () { return arity(flip('plus')) !== 2; }, 'key_map' => function () { return key_map('plus', [1 => 2, 4 => 8, 16 => 32]) !== [1 => 3, 4 => 12, 16 => 48]; }, 'flip1' => function () { return flip(array_(2), 1, 2) !== [2, 1]; }, 'flip2' => function () { return flip('map', [-1, -2], plus(5)) !== [4, 3]; }, 'compose1' => function ($x, $y, $z) { return call(compose(plus($x), mult($y)), $z) !== $x + $y * $z; }, 'compose2' => function ($x, $y, $z) { return call(compose(mult($x), plus($y)), $z) !== $x * ($y + $z); }, 'compose3' => function ($x, $y, $z) { $f = flip('map', [$x, $y]); $c = compose($f, 'plus'); return $c($z) !== [$x + $z, $y + $z]; }, 'compose4' => function ($n) { return call(compose('id', 'id'), $n) !== $n; }, 'compose5' => function ($x, $y, $z) { return call(compose(plus($x), plus($y)), $z) !== $x + $y + $z; }, 'compose6' => function ($x, $y, $z) {
} defun('implode_', 'implode'); defun('join_', implode_('')); defun('concat', function ($n) { return compose('join_', array_($n)); }); defun('thunk', function ($x, $_) { return $x; }); defun('nil', thunk([])); defuns(['filter' => flip(nary('array_filter', 2)), 'sum' => nary('array_sum', 1)]); defuns(['keys' => nary('array_keys', 1), 'values' => nary('array_values', 1), 'merge' => nary('array_merge', 2), 'foldr' => function ($f, $zero, $arr) { // Take args in a sane order return array_reduce($arr, $f, $zero); }, 'key_foldr' => function ($f, $zero) { return compose(foldr($f, $zero), key_map(array_(2))); }, 'subscript' => function ($x, $y) { return $x[$y]; }, 'take' => function ($n, $a) { return array_slice($a, 0, $n); }, 'cons' => function ($x, $y) { return merge([$x], $y); }, 'snoc' => function ($x, $y) { return merge($y, [$x]); }, 'echo_' => function ($x) { echo $x; return $x; }, 'id' => function ($x) { return $x; }, 'chain' => function ($x, $y, $z) { return $x($z, $y($z));