format(DATE_FORMAT); } function ssort($comparitor) { return function($array) use ($comparitor) { uasort($array, uncurry($comparitor)); return $array; }; } function uncurry($f) { return function($a, $b) use ($f) { return $f($a)($b); }; } function between($content, $start){ $r = explode($start, $content); if (isset($r[1])){ $r = explode($start, $r[1]); return $r[0]; } return ''; } const lines = 'lines'; function lines(string $string): array { return explode("\n", $string); } const glue = 'glue'; function glue(string $delim): callable { return function(array $strings) use ($delim): string { return implode($delim, $strings); }; } const unlines = 'unlines'; function unlines($lines) { return implode("\n", $lines); } const ununlines = 'ununlines'; function ununlines($lines) { return implode("\n\n", $lines); } const zipWith = 'zipWith'; function zipWith(callable $zipper, array $a, array $b) { return array_map($zipper, $a, $b); } function field($field) { return function($array) use ($field) { return $array[$field]; }; } const ⬄ = '⬄'; function ⬄($a) { return function($b) use ($a) { return $a <=> $b; }; } function ∘(...$fs) { return function($arg) use ($fs) { return array_reduce(array_reverse($fs), function($c, $f) { return $f($c); }, $arg); }; } function map($callable) { return function($list) use ($callable) { return array_map($callable, $list); }; } function aaray_column($column) { return function($array) use ($column) { return array_column($array, $column); }; } function aaray_slice($start) { return function($length) use ($start) { return function($array) use ($length, $start) { return array_slice($array, $start, $length); }; }; } function filter($callable) { return function($list) use ($callable) { return array_filter($list, $callable); }; } function f∘(callable $f) { return function(callable $g) use ($f) { return function($arg) use($g, $f) { return $f($g($arg)); }; }; } function ∘f(callable $f) { return function(callable $g) use ($f) { return function($arg) use($g, $f) { return $g($f($arg)); }; }; } function ∪($a, $b) { return array_merge($a, $b); } function closestIndex(int $n, array $list) { $a = map(function(int $v) use ($n) : int { return abs($v - $n); }) ($list); asort($a); return array_keys($a)[0]; } function closest(int $n, array $list) : int { return $list[closestIndex($n, $list)]; } function array_diff_assoc_recursive($array1, $array2) { $difference=array(); foreach($array1 as $key => $value) { if( is_array($value) ) { if( !isset($array2[$key]) || !is_array($array2[$key]) ) { $difference[$key] = $value; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if( !empty($new_diff) ) $difference[$key] = $new_diff; } } else if( !array_key_exists($key,$array2) || $array2[$key] !== $value ) { $difference[$key] = $value; } } return $difference; }