| @@ 81-87 (lines=7) @@ | ||
| 78 | * @param mixed $data |
|
| 79 | * @return boolean |
|
| 80 | */ |
|
| 81 | function is() { |
|
| 82 | static $is = false; |
|
| 83 | $is = $is ?: curry(function($type, $data) { |
|
| 84 | return 'Any' == $type || type($data) == $type; |
|
| 85 | }); |
|
| 86 | return _apply($is, func_get_args()); |
|
| 87 | } |
|
| 88 | ||
| 89 | /** |
|
| 90 | * Converts a variable to its string value. |
|
| @@ 100-106 (lines=7) @@ | ||
| 97 | * @param array $list |
|
| 98 | * @return array |
|
| 99 | */ |
|
| 100 | function reduce() { |
|
| 101 | static $reduce = false; |
|
| 102 | $reduce = $reduce ?: curry(function($fn, $initial, $list){ |
|
| 103 | return array_reduce($list, $fn, $initial); |
|
| 104 | }); |
|
| 105 | return _apply($reduce, func_get_args()); |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * Applies the callback to each item and returns the original list. |
|
| @@ 127-136 (lines=10) @@ | ||
| 124 | * @param array $list |
|
| 125 | * @return array |
|
| 126 | */ |
|
| 127 | function each() { |
|
| 128 | static $each = false; |
|
| 129 | $each = $each ?: curry(function($fn, $list){ |
|
| 130 | foreach ($list as $item) { |
|
| 131 | $fn($item); |
|
| 132 | } |
|
| 133 | return $list; |
|
| 134 | }); |
|
| 135 | return _apply($each, func_get_args()); |
|
| 136 | } |
|
| 137 | ||
| 138 | /** |
|
| 139 | * Returns the first item of the given array or string. |
|
| @@ 243-249 (lines=7) @@ | ||
| 240 | * @signature (a -> b) -> a -> a -> Boolean |
|
| 241 | * @return [type] [description] |
|
| 242 | */ |
|
| 243 | function equalBy() { |
|
| 244 | static $equalBy = false; |
|
| 245 | $equalBy = $equalBy ?: curry(function($fn, $a, $b) { |
|
| 246 | return _equals($fn($a), $fn($b)); |
|
| 247 | }); |
|
| 248 | return _apply($equalBy, func_get_args()); |
|
| 249 | } |
|
| 250 | ||
| 251 | /** |
|
| 252 | * Returns `$a < $b`. |
|
| @@ 273-281 (lines=9) @@ | ||
| 270 | * @param string $string |
|
| 271 | * @return array |
|
| 272 | */ |
|
| 273 | function match() { |
|
| 274 | static $match = false; |
|
| 275 | $match = $match ?: curry(function($pattern, $string) { |
|
| 276 | $results = []; |
|
| 277 | preg_match_all($pattern, $string, $results); |
|
| 278 | return $results[0]; |
|
| 279 | }); |
|
| 280 | return _apply($match, func_get_args()); |
|
| 281 | } |
|
| 282 | ||
| 283 | /** |
|
| 284 | * Curried version of `substr_count` with changed order of parameters, |
|