@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @param callable $fn |
| 89 | 89 | * @param int $argsCount |
| 90 | 90 | * @param array $boundArgs |
| 91 | - * @return callable |
|
| 91 | + * @return \Closure |
|
| 92 | 92 | */ |
| 93 | 93 | function _curried_function($fn, $argsCount, $boundArgs = []) { |
| 94 | 94 | return function() use($fn, $argsCount, $boundArgs) { |
@@ -158,8 +158,6 @@ discard block |
||
| 158 | 158 | * ``` |
| 159 | 159 | * |
| 160 | 160 | * @signature (*... -> a) -> [*] -> a |
| 161 | - * @param callable $fn |
|
| 162 | - * @param array $args |
|
| 163 | 161 | * @return mixed |
| 164 | 162 | */ |
| 165 | 163 | function apply() { |
@@ -181,7 +179,7 @@ discard block |
||
| 181 | 179 | * |
| 182 | 180 | * @signature (((a, b, ...) -> o), (o -> p), ..., (y -> z)) -> ((a, b, ...) -> z) |
| 183 | 181 | * @param callable ...$fns |
| 184 | - * @return callable |
|
| 182 | + * @return \Closure |
|
| 185 | 183 | */ |
| 186 | 184 | function pipe() { |
| 187 | 185 | $fns = func_get_args(); |
@@ -15,8 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | function _number_of_args($fn) { |
| 17 | 17 | $reflector = is_array($fn) ? |
| 18 | - new \ReflectionMethod($fn[0], $fn[1]) : |
|
| 19 | - new \ReflectionFunction($fn); |
|
| 18 | + new \ReflectionMethod($fn[0], $fn[1]) : new \ReflectionFunction($fn); |
|
| 20 | 19 | return $reflector->getNumberOfParameters(); |
| 21 | 20 | } |
| 22 | 21 | |
@@ -55,11 +54,11 @@ discard block |
||
| 55 | 54 | $i = 0; // index in $args |
| 56 | 55 | $k = 0; // index in rest |
| 57 | 56 | $restCount = $allArgsCount - $fnArgsCount; |
| 58 | - while($placeholdersCount > 0 && $k < $restCount) { |
|
| 57 | + while ($placeholdersCount > 0 && $k < $restCount) { |
|
| 59 | 58 | $arg = $rest[$k]; |
| 60 | - while(! _is_placeholder($args[$i])) |
|
| 61 | - $i++; |
|
| 62 | - if (! _is_placeholder($arg)) { |
|
| 59 | + while (!_is_placeholder($args[$i])) |
|
| 60 | + $i ++; |
|
| 61 | + if (!_is_placeholder($arg)) { |
|
| 63 | 62 | $args[$i] = $arg; |
| 64 | 63 | $placeholdersCount --; |
| 65 | 64 | } |
@@ -185,9 +184,9 @@ discard block |
||
| 185 | 184 | */ |
| 186 | 185 | function pipe() { |
| 187 | 186 | $fns = func_get_args(); |
| 188 | - if(count($fns) < 1) |
|
| 187 | + if (count($fns) < 1) |
|
| 189 | 188 | throw new InvalidArgument("pipe() requires at least one argument"); |
| 190 | - return curry(function () use ($fns) { |
|
| 189 | + return curry(function() use ($fns) { |
|
| 191 | 190 | $result = _apply(array_shift($fns), func_get_args()); |
| 192 | 191 | foreach ($fns as $fn) { |
| 193 | 192 | $result = $fn($result); |
@@ -57,8 +57,9 @@ discard block |
||
| 57 | 57 | $restCount = $allArgsCount - $fnArgsCount; |
| 58 | 58 | while($placeholdersCount > 0 && $k < $restCount) { |
| 59 | 59 | $arg = $rest[$k]; |
| 60 | - while(! _is_placeholder($args[$i])) |
|
| 61 | - $i++; |
|
| 60 | + while(! _is_placeholder($args[$i])) { |
|
| 61 | + $i++; |
|
| 62 | + } |
|
| 62 | 63 | if (! _is_placeholder($arg)) { |
| 63 | 64 | $args[$i] = $arg; |
| 64 | 65 | $placeholdersCount --; |
@@ -93,8 +94,9 @@ discard block |
||
| 93 | 94 | function _curried_function($fn, $argsCount, $boundArgs = []) { |
| 94 | 95 | return function() use($fn, $argsCount, $boundArgs) { |
| 95 | 96 | $merged = _merge_args($argsCount, $boundArgs, func_get_args()); |
| 96 | - if ($merged['count'] >= $argsCount) |
|
| 97 | - return call_user_func_array($fn, $merged['args']); |
|
| 97 | + if ($merged['count'] >= $argsCount) { |
|
| 98 | + return call_user_func_array($fn, $merged['args']); |
|
| 99 | + } |
|
| 98 | 100 | return _curried_function($fn, $argsCount, $merged['args']); |
| 99 | 101 | }; |
| 100 | 102 | } |
@@ -185,8 +187,9 @@ discard block |
||
| 185 | 187 | */ |
| 186 | 188 | function pipe() { |
| 187 | 189 | $fns = func_get_args(); |
| 188 | - if(count($fns) < 1) |
|
| 189 | - throw new InvalidArgument("pipe() requires at least one argument"); |
|
| 190 | + if(count($fns) < 1) { |
|
| 191 | + throw new InvalidArgument("pipe() requires at least one argument"); |
|
| 192 | + } |
|
| 190 | 193 | return curry(function () use ($fns) { |
| 191 | 194 | $result = _apply(array_shift($fns), func_get_args()); |
| 192 | 195 | foreach ($fns as $fn) { |
@@ -19,7 +19,6 @@ discard block |
||
| 19 | 19 | * ``` |
| 20 | 20 | * |
| 21 | 21 | * @signature a -> a |
| 22 | - * @param mixed $value |
|
| 23 | 22 | * @return mixed |
| 24 | 23 | */ |
| 25 | 24 | function clone_() { |
@@ -74,7 +73,6 @@ discard block |
||
| 74 | 73 | * ``` |
| 75 | 74 | * |
| 76 | 75 | * @signature {k: v} -> {k: v} |
| 77 | - * @param object $object |
|
| 78 | 76 | * @return array |
| 79 | 77 | */ |
| 80 | 78 | function attributes() { |
@@ -150,8 +148,6 @@ discard block |
||
| 150 | 148 | * ``` |
| 151 | 149 | * |
| 152 | 150 | * @signature k -> {k: v} -> Boolean |
| 153 | - * @param string|int $name |
|
| 154 | - * @param mixed $object |
|
| 155 | 151 | * @return bool |
| 156 | 152 | */ |
| 157 | 153 | function has() { |
@@ -180,8 +176,6 @@ discard block |
||
| 180 | 176 | * ``` |
| 181 | 177 | * |
| 182 | 178 | * @signature k -> {k: v} -> Maybe(v) |
| 183 | - * @param string $name |
|
| 184 | - * @param array $object |
|
| 185 | 179 | * @return mixed |
| 186 | 180 | */ |
| 187 | 181 | function get() { |
@@ -208,8 +202,6 @@ discard block |
||
| 208 | 202 | * ``` |
| 209 | 203 | * |
| 210 | 204 | * @signature [k] -> {k: v} -> v |
| 211 | - * @param array $path |
|
| 212 | - * @param mixed $object |
|
| 213 | 205 | * @return mixed |
| 214 | 206 | */ |
| 215 | 207 | function getPath() { |
@@ -232,9 +224,6 @@ discard block |
||
| 232 | 224 | * ``` |
| 233 | 225 | * |
| 234 | 226 | * @signature k -> v -> {k: v} -> {k: v} |
| 235 | - * @param string|int $name |
|
| 236 | - * @param mixed $value |
|
| 237 | - * @param mixed $object |
|
| 238 | 227 | * @return mixed |
| 239 | 228 | */ |
| 240 | 229 | function set() { |
@@ -257,9 +246,6 @@ discard block |
||
| 257 | 246 | * ``` |
| 258 | 247 | * |
| 259 | 248 | * @signature (a -> Boolean) -> k -> {k : a} -> Boolean |
| 260 | - * @param callable $predicate |
|
| 261 | - * @param string|int $key |
|
| 262 | - * @param mixed $object |
|
| 263 | 249 | * @return bool |
| 264 | 250 | */ |
| 265 | 251 | function check() { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | 157 | function has() { |
| 158 | - $has = function($name, $object){ |
|
| 158 | + $has = function($name, $object) { |
|
| 159 | 159 | return contains($name, keys($object)); |
| 160 | 160 | }; |
| 161 | 161 | return apply(curry($has), func_get_args()); |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * @return mixed |
| 186 | 186 | */ |
| 187 | 187 | function get() { |
| 188 | - $get = function($name, $object){ |
|
| 188 | + $get = function($name, $object) { |
|
| 189 | 189 | $object = attributes($object); |
| 190 | 190 | return has($name, $object) |
| 191 | 191 | ? $object[$name] |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @return mixed |
| 214 | 214 | */ |
| 215 | 215 | function getPath() { |
| 216 | - $getPath = function($path, $object){ |
|
| 216 | + $getPath = function($path, $object) { |
|
| 217 | 217 | |
| 218 | 218 | }; |
| 219 | 219 | return apply(curry($getPath), func_get_args()); |
@@ -8,8 +8,6 @@ discard block |
||
| 8 | 8 | * Returns `$a && $b`. |
| 9 | 9 | * |
| 10 | 10 | * @signature Boolean -> Boolean -> Boolean |
| 11 | - * @param bool $a |
|
| 12 | - * @param bool $b |
|
| 13 | 11 | * @return bool |
| 14 | 12 | */ |
| 15 | 13 | function and_() { |
@@ -22,8 +20,6 @@ discard block |
||
| 22 | 20 | * Returns `$a || $b`. |
| 23 | 21 | * |
| 24 | 22 | * @signature Boolean -> Boolean -> Boolean |
| 25 | - * @param bool $a |
|
| 26 | - * @param bool $b |
|
| 27 | 23 | * @return bool |
| 28 | 24 | */ |
| 29 | 25 | function or_() { |
@@ -36,7 +32,6 @@ discard block |
||
| 36 | 32 | * Returns `!$x`. |
| 37 | 33 | * |
| 38 | 34 | * @signature Boolean -> Boolean |
| 39 | - * @param bool $x |
|
| 40 | 35 | * @return bool |
| 41 | 36 | */ |
| 42 | 37 | function not() { |
@@ -50,8 +45,6 @@ discard block |
||
| 50 | 45 | * Returns `$x == $y`. |
| 51 | 46 | * |
| 52 | 47 | * @signature * -> * -> Boolean |
| 53 | - * @param mixed $a |
|
| 54 | - * @param mixed $b |
|
| 55 | 48 | * @return bool |
| 56 | 49 | */ |
| 57 | 50 | function eq() { |
@@ -64,8 +57,6 @@ discard block |
||
| 64 | 57 | * Returns `$x != $y`. |
| 65 | 58 | * |
| 66 | 59 | * @signature * -> * -> Boolean |
| 67 | - * @param mixed $a |
|
| 68 | - * @param mixed $b |
|
| 69 | 60 | * @return bool |
| 70 | 61 | */ |
| 71 | 62 | function notEq() { |
@@ -78,8 +69,6 @@ discard block |
||
| 78 | 69 | * Returns `$x === $y`. |
| 79 | 70 | * |
| 80 | 71 | * @signature * -> * -> Boolean |
| 81 | - * @param mixed $a |
|
| 82 | - * @param mixed $b |
|
| 83 | 72 | * @return bool |
| 84 | 73 | */ |
| 85 | 74 | function eqq() { |
@@ -92,8 +81,6 @@ discard block |
||
| 92 | 81 | * Returns `$x !== $y`. |
| 93 | 82 | * |
| 94 | 83 | * @signature * -> * -> Boolean |
| 95 | - * @param mixed $a |
|
| 96 | - * @param mixed $b |
|
| 97 | 84 | * @return bool |
| 98 | 85 | */ |
| 99 | 86 | function notEqq() { |
@@ -118,8 +105,6 @@ discard block |
||
| 118 | 105 | * ``` |
| 119 | 106 | * |
| 120 | 107 | * @signature * -> * -> Boolean |
| 121 | - * @param mixed $a |
|
| 122 | - * @param mixed $b |
|
| 123 | 108 | * @return bool |
| 124 | 109 | */ |
| 125 | 110 | function equals() { |
@@ -157,8 +142,6 @@ discard block |
||
| 157 | 142 | * Returns `$a < $b`. |
| 158 | 143 | * |
| 159 | 144 | * @signature * -> * -> Boolean |
| 160 | - * @param mixed $a |
|
| 161 | - * @param mixed $b |
|
| 162 | 145 | * @return bool |
| 163 | 146 | */ |
| 164 | 147 | function lt() { |
@@ -171,8 +154,6 @@ discard block |
||
| 171 | 154 | * Returns `$a <= $b`. |
| 172 | 155 | * |
| 173 | 156 | * @signature * -> * -> Boolean |
| 174 | - * @param mixed $a |
|
| 175 | - * @param mixed $b |
|
| 176 | 157 | * @return bool |
| 177 | 158 | */ |
| 178 | 159 | function lte() { |
@@ -185,8 +166,6 @@ discard block |
||
| 185 | 166 | * Returns `$a > $b`. |
| 186 | 167 | * |
| 187 | 168 | * @signature * -> * -> Boolean |
| 188 | - * @param mixed $a |
|
| 189 | - * @param mixed $b |
|
| 190 | 169 | * @return bool |
| 191 | 170 | */ |
| 192 | 171 | function gt() { |
@@ -199,8 +178,6 @@ discard block |
||
| 199 | 178 | * Returns `$a >= $b`. |
| 200 | 179 | * |
| 201 | 180 | * @signature * -> * -> Boolean |
| 202 | - * @param mixed $a |
|
| 203 | - * @param mixed $b |
|
| 204 | 181 | * @return bool |
| 205 | 182 | */ |
| 206 | 183 | function gte() { |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * @return bool |
| 14 | 14 | */ |
| 15 | 15 | function and_() { |
| 16 | - return apply(curry(function($a, $b){ |
|
| 16 | + return apply(curry(function($a, $b) { |
|
| 17 | 17 | return $a && $b; |
| 18 | 18 | }), func_get_args()); |
| 19 | 19 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @return bool |
| 28 | 28 | */ |
| 29 | 29 | function or_() { |
| 30 | - return apply(curry(function($a, $b){ |
|
| 30 | + return apply(curry(function($a, $b) { |
|
| 31 | 31 | return $a || $b; |
| 32 | 32 | }), func_get_args()); |
| 33 | 33 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | 57 | function eq() { |
| 58 | - return apply(curry(function($a, $b){ |
|
| 58 | + return apply(curry(function($a, $b) { |
|
| 59 | 59 | return $a == $b; |
| 60 | 60 | }), func_get_args()); |
| 61 | 61 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return bool |
| 70 | 70 | */ |
| 71 | 71 | function notEq() { |
| 72 | - return apply(curry(function($a, $b){ |
|
| 72 | + return apply(curry(function($a, $b) { |
|
| 73 | 73 | return $a != $b; |
| 74 | 74 | }), func_get_args()); |
| 75 | 75 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | 85 | function eqq() { |
| 86 | - return apply(curry(function($a, $b){ |
|
| 86 | + return apply(curry(function($a, $b) { |
|
| 87 | 87 | return $a === $b; |
| 88 | 88 | }), func_get_args()); |
| 89 | 89 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return bool |
| 98 | 98 | */ |
| 99 | 99 | function notEqq() { |
| 100 | - return apply(curry(function($a, $b){ |
|
| 100 | + return apply(curry(function($a, $b) { |
|
| 101 | 101 | return $a !== $b; |
| 102 | 102 | }), func_get_args()); |
| 103 | 103 | } |
@@ -140,9 +140,7 @@ discard block |
||
| 140 | 140 | return $a == $b; |
| 141 | 141 | case 'List': |
| 142 | 142 | $length = length($a); |
| 143 | - return length($b) != $length ? false : |
|
| 144 | - 0 == $length ? true : |
|
| 145 | - equals(head($a), head($b)) && equals(tail($a), tail($b)); |
|
| 143 | + return length($b) != $length ? false : 0 == $length ? true : equals(head($a), head($b)) && equals(tail($a), tail($b)); |
|
| 146 | 144 | case 'Array': |
| 147 | 145 | case 'ArrayObject': |
| 148 | 146 | case 'Object': |
@@ -162,7 +160,7 @@ discard block |
||
| 162 | 160 | * @return bool |
| 163 | 161 | */ |
| 164 | 162 | function lt() { |
| 165 | - return apply(curry(function($a, $b){ |
|
| 163 | + return apply(curry(function($a, $b) { |
|
| 166 | 164 | return $a < $b; |
| 167 | 165 | }), func_get_args()); |
| 168 | 166 | } |
@@ -176,7 +174,7 @@ discard block |
||
| 176 | 174 | * @return bool |
| 177 | 175 | */ |
| 178 | 176 | function lte() { |
| 179 | - return apply(curry(function($a, $b){ |
|
| 177 | + return apply(curry(function($a, $b) { |
|
| 180 | 178 | return $a <= $b; |
| 181 | 179 | }), func_get_args()); |
| 182 | 180 | } |
@@ -190,7 +188,7 @@ discard block |
||
| 190 | 188 | * @return bool |
| 191 | 189 | */ |
| 192 | 190 | function gt() { |
| 193 | - return apply(curry(function($a, $b){ |
|
| 191 | + return apply(curry(function($a, $b) { |
|
| 194 | 192 | return $a > $b; |
| 195 | 193 | }), func_get_args()); |
| 196 | 194 | } |
@@ -204,7 +202,7 @@ discard block |
||
| 204 | 202 | * @return bool |
| 205 | 203 | */ |
| 206 | 204 | function gte() { |
| 207 | - return apply(curry(function($a, $b){ |
|
| 205 | + return apply(curry(function($a, $b) { |
|
| 208 | 206 | return $a >= $b; |
| 209 | 207 | }), func_get_args()); |
| 210 | 208 | } |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Placeholder { |
| 10 | 10 | private static $instance; |
| 11 | - private function __construct(){} |
|
| 11 | + private function __construct() {} |
|
| 12 | 12 | public static function get() |
| 13 | 13 | { |
| 14 | - if(static::$instance === null) |
|
| 14 | + if (static::$instance === null) |
|
| 15 | 15 | static::$instance = new Placeholder; |
| 16 | 16 | return static::$instance; |
| 17 | 17 | } |
| 18 | - public function __toString(){ |
|
| 18 | + public function __toString() { |
|
| 19 | 19 | return '__'; |
| 20 | 20 | } |
| 21 | 21 | } |
@@ -11,8 +11,9 @@ |
||
| 11 | 11 | private function __construct(){} |
| 12 | 12 | public static function get() |
| 13 | 13 | { |
| 14 | - if(static::$instance === null) |
|
| 15 | - static::$instance = new Placeholder; |
|
| 14 | + if(static::$instance === null) { |
|
| 15 | + static::$instance = new Placeholder; |
|
| 16 | + } |
|
| 16 | 17 | return static::$instance; |
| 17 | 18 | } |
| 18 | 19 | public function __toString(){ |
@@ -2,8 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | function numberOfArgs($fn) { |
| 4 | 4 | $reflector = is_array($fn) ? |
| 5 | - new ReflectionMethod($fn[0], $fn[1]) : |
|
| 6 | - new ReflectionFunction($fn); |
|
| 5 | + new ReflectionMethod($fn[0], $fn[1]) : new ReflectionFunction($fn); |
|
| 7 | 6 | return $reflector->getNumberOfParameters(); |
| 8 | 7 | } |
| 9 | 8 | |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | function curriedFunction($fn, $argsCount, $boundArgs = []) { |
| 15 | 15 | return function() use($fn, $argsCount, $boundArgs) { |
| 16 | 16 | $boundArgs = array_merge($boundArgs, func_get_args()); |
| 17 | - if (count($boundArgs) >= $argsCount) |
|
| 18 | - return call_user_func_array($fn, $boundArgs); |
|
| 17 | + if (count($boundArgs) >= $argsCount) { |
|
| 18 | + return call_user_func_array($fn, $boundArgs); |
|
| 19 | + } |
|
| 19 | 20 | return curriedFunction($fn, $argsCount, $boundArgs); |
| 20 | 21 | }; |
| 21 | 22 | } |