@@ -97,8 +97,9 @@ |
||
| 97 | 97 | function equals() { |
| 98 | 98 | $equals = function($a, $b) { |
| 99 | 99 | $type = type($a); |
| 100 | - if ($type != type($b)) |
|
| 101 | - return false; |
|
| 100 | + if ($type != type($b)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 102 | 103 | switch ($type) { |
| 103 | 104 | case 'Null': |
| 104 | 105 | case 'Boolean': |
@@ -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() { |
@@ -72,8 +72,9 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function attributes() { |
| 74 | 74 | $attrs = function($object) { |
| 75 | - if (is_object($object)) |
|
| 76 | - return get_object_vars($object); |
|
| 75 | + if (is_object($object)) { |
|
| 76 | + return get_object_vars($object); |
|
| 77 | + } |
|
| 77 | 78 | return $object; |
| 78 | 79 | }; |
| 79 | 80 | return apply(curry($attrs), func_get_args()); |
@@ -208,8 +209,9 @@ discard block |
||
| 208 | 209 | function getPath() { |
| 209 | 210 | $getPath = function($path, $object){ |
| 210 | 211 | return reduce(function($result, $name) { |
| 211 | - if ($result !== null) |
|
| 212 | - $result = get($name, $result); |
|
| 212 | + if ($result !== null) { |
|
| 213 | + $result = get($name, $result); |
|
| 214 | + } |
|
| 213 | 215 | return $result; |
| 214 | 216 | }, $object, $path); |
| 215 | 217 | }; |
@@ -237,10 +239,11 @@ discard block |
||
| 237 | 239 | function set() { |
| 238 | 240 | $set = function($name, $value, $object) { |
| 239 | 241 | $object = clone_($object); |
| 240 | - if (is_object($object)) |
|
| 241 | - $object->{$name} = $value; |
|
| 242 | - else |
|
| 243 | - $object[$name] = $value; |
|
| 242 | + if (is_object($object)) { |
|
| 243 | + $object->{$name} = $value; |
|
| 244 | + } else { |
|
| 245 | + $object[$name] = $value; |
|
| 246 | + } |
|
| 244 | 247 | return $object; |
| 245 | 248 | }; |
| 246 | 249 | return apply(curry($set), func_get_args()); |
@@ -22,7 +22,6 @@ discard block |
||
| 22 | 22 | * ``` |
| 23 | 23 | * |
| 24 | 24 | * @signature a -> a |
| 25 | - * @param mixed $value |
|
| 26 | 25 | * @return mixed |
| 27 | 26 | */ |
| 28 | 27 | function clone_() { |
@@ -73,7 +72,6 @@ discard block |
||
| 73 | 72 | * |
| 74 | 73 | * @stream |
| 75 | 74 | * @signature {k: v} -> {k: v} |
| 76 | - * @param object|array $object |
|
| 77 | 75 | * @return array |
| 78 | 76 | */ |
| 79 | 77 | function attributes() { |
@@ -98,7 +96,6 @@ discard block |
||
| 98 | 96 | * @stream |
| 99 | 97 | * @signature [*] -> [Number] |
| 100 | 98 | * @signature {k: v} -> [k] |
| 101 | - * @param object|array $object |
|
| 102 | 99 | * @return array |
| 103 | 100 | */ |
| 104 | 101 | function keys() { |
@@ -121,7 +118,6 @@ discard block |
||
| 121 | 118 | * @stream |
| 122 | 119 | * @signature [a] -> [a] |
| 123 | 120 | * @signature {k: v} -> [v] |
| 124 | - * @param object|array $object |
|
| 125 | 121 | * @return array |
| 126 | 122 | */ |
| 127 | 123 | function values() { |
@@ -162,8 +158,6 @@ discard block |
||
| 162 | 158 | * |
| 163 | 159 | * @stream |
| 164 | 160 | * @signature k -> {k: v} -> Boolean |
| 165 | - * @param string|int $name |
|
| 166 | - * @param mixed $object |
|
| 167 | 161 | * @return bool |
| 168 | 162 | */ |
| 169 | 163 | function has() { |
@@ -195,8 +189,6 @@ discard block |
||
| 195 | 189 | * |
| 196 | 190 | * @stream |
| 197 | 191 | * @signature k -> {k: v} -> Maybe(v) |
| 198 | - * @param string $name |
|
| 199 | - * @param array $object |
|
| 200 | 192 | * @return mixed |
| 201 | 193 | */ |
| 202 | 194 | function get() { |
@@ -227,8 +219,6 @@ discard block |
||
| 227 | 219 | * |
| 228 | 220 | * @stream |
| 229 | 221 | * @signature [k] -> {k: v} -> v |
| 230 | - * @param array $path |
|
| 231 | - * @param mixed $object |
|
| 232 | 222 | * @return mixed |
| 233 | 223 | */ |
| 234 | 224 | function getPath() { |
@@ -259,9 +249,6 @@ discard block |
||
| 259 | 249 | * |
| 260 | 250 | * @stream |
| 261 | 251 | * @signature k -> v -> {k: v} -> {k: v} |
| 262 | - * @param string|int $name |
|
| 263 | - * @param mixed $value |
|
| 264 | - * @param mixed $object |
|
| 265 | 252 | * @return mixed |
| 266 | 253 | */ |
| 267 | 254 | function set() { |
@@ -293,9 +280,6 @@ discard block |
||
| 293 | 280 | * |
| 294 | 281 | * @stream |
| 295 | 282 | * @signature k -> (v -> v) -> {k: v} -> {k: v} |
| 296 | - * @param string|int $name |
|
| 297 | - * @param callable $fn |
|
| 298 | - * @param mixed $object |
|
| 299 | 283 | * @return mixed |
| 300 | 284 | */ |
| 301 | 285 | function update() { |
@@ -321,9 +305,6 @@ discard block |
||
| 321 | 305 | * |
| 322 | 306 | * @stream |
| 323 | 307 | * @signature (a -> Boolean) -> k -> {k : a} -> Boolean |
| 324 | - * @param callable $predicate |
|
| 325 | - * @param string|int $key |
|
| 326 | - * @param mixed $object |
|
| 327 | 308 | * @return bool |
| 328 | 309 | */ |
| 329 | 310 | function satisfies() { |
@@ -356,8 +337,6 @@ discard block |
||
| 356 | 337 | * |
| 357 | 338 | * @stream |
| 358 | 339 | * @signature {String: (a -> Boolean)} -> {k : a} -> Boolean |
| 359 | - * @param array $predicates |
|
| 360 | - * @param mixed $object |
|
| 361 | 340 | * @return bool |
| 362 | 341 | */ |
| 363 | 342 | function satisfiesAll() { |
@@ -394,8 +373,6 @@ discard block |
||
| 394 | 373 | * |
| 395 | 374 | * @stream |
| 396 | 375 | * @signature {String: (a -> Boolean)} -> {k : a} -> Boolean |
| 397 | - * @param array $predicates |
|
| 398 | - * @param mixed $object |
|
| 399 | 376 | * @return bool |
| 400 | 377 | */ |
| 401 | 378 | function satisfiesAny() { |
@@ -420,7 +397,6 @@ discard block |
||
| 420 | 397 | * |
| 421 | 398 | * @stream |
| 422 | 399 | * @signature {k: v} -> [(k,v)] |
| 423 | - * @param array $object |
|
| 424 | 400 | * @return array |
| 425 | 401 | */ |
| 426 | 402 | function toPairs() { |
@@ -634,8 +634,6 @@ discard block |
||
| 634 | 634 | * Gets an element of the stream methods list. |
| 635 | 635 | * |
| 636 | 636 | * @signature String -> Block -> String |
| 637 | - * @param string $moduleName |
|
| 638 | - * @param object $block |
|
| 639 | 637 | * @return string |
| 640 | 638 | */ |
| 641 | 639 | function stream_method_link() { |
@@ -661,7 +659,6 @@ discard block |
||
| 661 | 659 | * Dump a variable and returns it. |
| 662 | 660 | * |
| 663 | 661 | * @signature a -> a |
| 664 | - * @param mixed $something |
|
| 665 | 662 | * @return mixed |
| 666 | 663 | */ |
| 667 | 664 | function log() { |
@@ -148,14 +148,16 @@ discard block |
||
| 148 | 148 | function write_module($module) { |
| 149 | 149 | if ($module->docs) { |
| 150 | 150 | $docsDir = dirname($module->docsPath); |
| 151 | - if (!is_dir($docsDir)) |
|
| 152 | - mkdir($docsDir, 0777, true); |
|
| 151 | + if (!is_dir($docsDir)) { |
|
| 152 | + mkdir($docsDir, 0777, true); |
|
| 153 | + } |
|
| 153 | 154 | file_put_contents($module->docsPath, $module->docs); |
| 154 | 155 | } |
| 155 | 156 | if ($module->tests) { |
| 156 | 157 | $testsDir = dirname($module->testsPath); |
| 157 | - if (!is_dir($testsDir)) |
|
| 158 | - mkdir($testsDir, 0777, true); |
|
| 158 | + if (!is_dir($testsDir)) { |
|
| 159 | + mkdir($testsDir, 0777, true); |
|
| 160 | + } |
|
| 159 | 161 | file_put_contents($module->testsPath, $module->tests); |
| 160 | 162 | } |
| 161 | 163 | if ($module->streamOperations) { |
@@ -252,9 +254,15 @@ discard block |
||
| 252 | 254 | $tags = groupBy(get('name'), tags_of($doxBlock)); |
| 253 | 255 | |
| 254 | 256 | $type = 'function'; |
| 255 | - if (has('file', $tags)) $type = 'file'; |
|
| 256 | - if (has('class', $tags)) $type = 'class'; |
|
| 257 | - if (has('method', $tags)) $type = 'method'; |
|
| 257 | + if (has('file', $tags)) { |
|
| 258 | + $type = 'file'; |
|
| 259 | + } |
|
| 260 | + if (has('class', $tags)) { |
|
| 261 | + $type = 'class'; |
|
| 262 | + } |
|
| 263 | + if (has('method', $tags)) { |
|
| 264 | + $type = 'method'; |
|
| 265 | + } |
|
| 258 | 266 | |
| 259 | 267 | $params = map(function($tag){ |
| 260 | 268 | $parts = split(' ', get('value', $tag)); |
@@ -266,8 +274,9 @@ discard block |
||
| 266 | 274 | |
| 267 | 275 | $return = getPath(['return', 0, 'value'], $tags); |
| 268 | 276 | $signatures = get('signature', $tags); |
| 269 | - if ($signatures) |
|
| 270 | - $signatures = map(get('value'), $signatures); |
|
| 277 | + if ($signatures) { |
|
| 278 | + $signatures = map(get('value'), $signatures); |
|
| 279 | + } |
|
| 271 | 280 | return (object) [ |
| 272 | 281 | 'type' => $type, |
| 273 | 282 | 'name' => getPath(['ctx', 'name'], $doxBlock), |
@@ -291,12 +300,13 @@ discard block |
||
| 291 | 300 | * @return array |
| 292 | 301 | */ |
| 293 | 302 | function tags_of($doxBlock) { |
| 294 | - if ($doxBlock->tags) |
|
| 295 | - return map(function($tag){ |
|
| 303 | + if ($doxBlock->tags) { |
|
| 304 | + return map(function($tag){ |
|
| 296 | 305 | return (object) [ |
| 297 | 306 | 'name' => $tag->type, |
| 298 | 307 | 'value' => $tag->string |
| 299 | 308 | ]; |
| 309 | + } |
|
| 300 | 310 | }, $doxBlock->tags); |
| 301 | 311 | return []; |
| 302 | 312 | } |
@@ -310,8 +320,9 @@ discard block |
||
| 310 | 320 | */ |
| 311 | 321 | function generate_docs($module) { |
| 312 | 322 | $module->docs = ''; |
| 313 | - if (startsWith('_', $module->name)) |
|
| 314 | - return $module; |
|
| 323 | + if (startsWith('_', $module->name)) { |
|
| 324 | + return $module; |
|
| 325 | + } |
|
| 315 | 326 | return apply(process_of([ |
| 316 | 327 | 'generate_docs_header', |
| 317 | 328 | 'generate_docs_sommaire', |
@@ -388,15 +399,17 @@ discard block |
||
| 388 | 399 | * @return string |
| 389 | 400 | */ |
| 390 | 401 | function generate_docs_contents_item($block) { |
| 391 | - if ($block->type != 'function') |
|
| 392 | - return ''; |
|
| 402 | + if ($block->type != 'function') { |
|
| 403 | + return ''; |
|
| 404 | + } |
|
| 393 | 405 | $params = join(', ', map(pipe(values(), join(' ')), get('params', $block))); |
| 394 | 406 | $return = get('return', $block); |
| 395 | 407 | $prototype = "```php\n{$block->name}({$params}) : {$return}\n```\n\n"; |
| 396 | 408 | $signature = ''; |
| 397 | 409 | $blockSignature = join("\n", $block->signatures); |
| 398 | - if ($blockSignature) |
|
| 399 | - $signature = "```\n{$blockSignature}\n```\n\n"; |
|
| 410 | + if ($blockSignature) { |
|
| 411 | + $signature = "```\n{$blockSignature}\n```\n\n"; |
|
| 412 | + } |
|
| 400 | 413 | return "# {$block->name}\n\n{$prototype}{$signature}{$block->description}\n\n"; |
| 401 | 414 | } |
| 402 | 415 | |
@@ -427,8 +440,9 @@ discard block |
||
| 427 | 440 | function generate_tests_header($module) { |
| 428 | 441 | $namespace = "Tarsana\UnitTests\Functional"; |
| 429 | 442 | $additionalNamespace = replace("/", "\\", remove(6, dirname($module->testsPath))); |
| 430 | - if ($additionalNamespace) |
|
| 431 | - $namespace .= "\\" . $additionalNamespace; |
|
| 443 | + if ($additionalNamespace) { |
|
| 444 | + $namespace .= "\\" . $additionalNamespace; |
|
| 445 | + } |
|
| 432 | 446 | $name = remove(-4, last(split("/", $module->testsPath))); |
| 433 | 447 | $module->tests .= "<?php namespace {$namespace};\n\nuse Tarsana\Functional as F;\n\nclass {$name} extends \Tarsana\UnitTests\Functional\UnitTest {\n"; |
| 434 | 448 | return $module; |
@@ -449,10 +463,11 @@ discard block |
||
| 449 | 463 | $contents = join("\n", map(function($block) use($module) { |
| 450 | 464 | return generate_tests_contents_item($block, $module); |
| 451 | 465 | }, $blocks)); |
| 452 | - if (trim($contents) != '') |
|
| 453 | - $module->tests .= $contents; |
|
| 454 | - else |
|
| 455 | - $module->tests = ''; |
|
| 466 | + if (trim($contents) != '') { |
|
| 467 | + $module->tests .= $contents; |
|
| 468 | + } else { |
|
| 469 | + $module->tests = ''; |
|
| 470 | + } |
|
| 456 | 471 | return $module; |
| 457 | 472 | } |
| 458 | 473 | |
@@ -465,8 +480,9 @@ discard block |
||
| 465 | 480 | * @return string |
| 466 | 481 | */ |
| 467 | 482 | function generate_tests_contents_item($block, $module) { |
| 468 | - if ($block->type != 'function') |
|
| 469 | - return ''; |
|
| 483 | + if ($block->type != 'function') { |
|
| 484 | + return ''; |
|
| 485 | + } |
|
| 470 | 486 | |
| 471 | 487 | $code = apply(pipe( |
| 472 | 488 | _f('code_from_description'), |
@@ -480,8 +496,9 @@ discard block |
||
| 480 | 496 | join("\n") |
| 481 | 497 | ), [$block]); |
| 482 | 498 | |
| 483 | - if ('' == trim($code)) |
|
| 484 | - return ''; |
|
| 499 | + if ('' == trim($code)) { |
|
| 500 | + return ''; |
|
| 501 | + } |
|
| 485 | 502 | return prepend("\tpublic function test_{$block->name}() {\n", |
| 486 | 503 | append("\n\t}\n", $code) |
| 487 | 504 | ); |
@@ -496,8 +513,9 @@ discard block |
||
| 496 | 513 | */ |
| 497 | 514 | function code_from_description($block) { |
| 498 | 515 | $description = get('description', $block); |
| 499 | - if (!contains('```php', $description)) |
|
| 500 | - return ''; |
|
| 516 | + if (!contains('```php', $description)) { |
|
| 517 | + return ''; |
|
| 518 | + } |
|
| 501 | 519 | $code = remove(7 + indexOf('```php', $description), $description); |
| 502 | 520 | return remove(-4, trim($code)); |
| 503 | 521 | } |
@@ -513,8 +531,7 @@ discard block |
||
| 513 | 531 | if (contains('; //=> ', $part)) { |
| 514 | 532 | $pieces = split('; //=> ', $part); |
| 515 | 533 | $part = "\$this->assertEquals({$pieces[1]}, {$pieces[0]});"; |
| 516 | - } |
|
| 517 | - elseif (contains('; // throws ', $part)) { |
|
| 534 | + } elseif (contains('; // throws ', $part)) { |
|
| 518 | 535 | $pieces = split('; // throws ', $part); |
| 519 | 536 | $variables = match('/ \$[0-9a-zA-Z_]+/', $pieces[0]); |
| 520 | 537 | $use = ''; |
@@ -523,8 +540,7 @@ discard block |
||
| 523 | 540 | $use = "use({$variables}) "; |
| 524 | 541 | } |
| 525 | 542 | return "\$this->assertErrorThrown(function() {$use}{\n\t$pieces[0]; \n},\n{$pieces[1]});"; |
| 526 | - } |
|
| 527 | - elseif (startsWith('class ', $part) || startsWith('function ', $part)) { |
|
| 543 | + } elseif (startsWith('class ', $part) || startsWith('function ', $part)) { |
|
| 528 | 544 | $module->testsFooter .= $part . "\n\n"; |
| 529 | 545 | $part = ''; |
| 530 | 546 | } |
@@ -539,8 +555,9 @@ discard block |
||
| 539 | 555 | * @return object |
| 540 | 556 | */ |
| 541 | 557 | function generate_tests_footer($module) { |
| 542 | - if ($module->tests) |
|
| 543 | - $module->tests .= "}\n\n{$module->testsFooter}"; |
|
| 558 | + if ($module->tests) { |
|
| 559 | + $module->tests .= "}\n\n{$module->testsFooter}"; |
|
| 560 | + } |
|
| 544 | 561 | return $module; |
| 545 | 562 | } |
| 546 | 563 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Creates a new Stream. |
| 37 | 37 | * |
| 38 | 38 | * @param mixed $data |
| 39 | - * @return Tarsana\Functional\Stream |
|
| 39 | + * @return Stream |
|
| 40 | 40 | */ |
| 41 | 41 | public static function of($data) |
| 42 | 42 | { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * Adds a new operation to the Stream class. |
| 48 | 48 | * |
| 49 | 49 | * @param string $name |
| 50 | - * @param string $signature |
|
| 50 | + * @param string $signatures |
|
| 51 | 51 | * @param callable $fn |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * Checks if the Stream class has an operation with the given name. |
| 66 | 66 | * |
| 67 | 67 | * @param string $name |
| 68 | - * @return boolean |
|
| 68 | + * @return \PHPUnit_Framework_Constraint_TraversableContains |
|
| 69 | 69 | */ |
| 70 | 70 | public static function hasOperation($name) |
| 71 | 71 | { |
@@ -87,7 +87,6 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * Creates a new Stream with some data. |
| 89 | 89 | * |
| 90 | - * @param mixed $data |
|
| 91 | 90 | */ |
| 92 | 91 | protected function __construct($stream) |
| 93 | 92 | { |
@@ -120,7 +119,7 @@ discard block |
||
| 120 | 119 | * |
| 121 | 120 | * @param string $name The name of the operation |
| 122 | 121 | * @param array $args |
| 123 | - * @return Tarsana\Functional\Stream |
|
| 122 | + * @return Stream |
|
| 124 | 123 | */ |
| 125 | 124 | public function __call($name, $args) |
| 126 | 125 | { |
@@ -26,7 +26,6 @@ discard block |
||
| 26 | 26 | * ``` |
| 27 | 27 | * |
| 28 | 28 | * @signature * -> String |
| 29 | - * @param mixed $data |
|
| 30 | 29 | * @return string |
| 31 | 30 | */ |
| 32 | 31 | function type() { |
@@ -73,8 +72,6 @@ discard block |
||
| 73 | 72 | * |
| 74 | 73 | * @stream |
| 75 | 74 | * @signature String -> * -> Boolean |
| 76 | - * @param string $type |
|
| 77 | - * @param mixed $data |
|
| 78 | 75 | * @return boolean |
| 79 | 76 | */ |
| 80 | 77 | function is() { |
@@ -109,7 +106,6 @@ discard block |
||
| 109 | 106 | * |
| 110 | 107 | * @stream |
| 111 | 108 | * @signature * -> String |
| 112 | - * @param mixed $something |
|
| 113 | 109 | * @return string |
| 114 | 110 | */ |
| 115 | 111 | function toString () { |
@@ -32,9 +32,15 @@ discard block |
||
| 32 | 32 | function type() { |
| 33 | 33 | static $type = false; |
| 34 | 34 | $type = $type ?: curry(function($data) { |
| 35 | - if ($data instanceof Error) return 'Error'; |
|
| 36 | - if ($data instanceof Stream) return "Stream"; |
|
| 37 | - if (is_callable($data)) return 'Function'; |
|
| 35 | + if ($data instanceof Error) { |
|
| 36 | + return 'Error'; |
|
| 37 | + } |
|
| 38 | + if ($data instanceof Stream) { |
|
| 39 | + return "Stream"; |
|
| 40 | + } |
|
| 41 | + if (is_callable($data)) { |
|
| 42 | + return 'Function'; |
|
| 43 | + } |
|
| 38 | 44 | switch (gettype($data)) { |
| 39 | 45 | case 'boolean': |
| 40 | 46 | return 'Boolean'; |
@@ -48,8 +54,9 @@ discard block |
||
| 48 | 54 | case 'resource': |
| 49 | 55 | return 'Resource'; |
| 50 | 56 | case 'array': |
| 51 | - if (allSatisfies('is_numeric', keys($data))) |
|
| 52 | - return 'List'; |
|
| 57 | + if (allSatisfies('is_numeric', keys($data))) { |
|
| 58 | + return 'List'; |
|
| 59 | + } |
|
| 53 | 60 | return 'Array'; |
| 54 | 61 | case 'object': |
| 55 | 62 | return 'Object'; |
@@ -65,8 +65,6 @@ discard block |
||
| 65 | 65 | * ``` |
| 66 | 66 | * |
| 67 | 67 | * @signature (*... -> a) -> [*] -> a |
| 68 | - * @param callable $fn |
|
| 69 | - * @param array $args |
|
| 70 | 68 | * @return mixed |
| 71 | 69 | */ |
| 72 | 70 | function apply() { |
@@ -89,7 +87,6 @@ discard block |
||
| 89 | 87 | * ``` |
| 90 | 88 | * |
| 91 | 89 | * @signature (((a, b, ...) -> o), (o -> p), ..., (y -> z)) -> ((a, b, ...) -> z) |
| 92 | - * @param callable $fns... |
|
| 93 | 90 | * @return callable |
| 94 | 91 | */ |
| 95 | 92 | function pipe() { |
@@ -137,7 +134,6 @@ discard block |
||
| 137 | 134 | * ``` |
| 138 | 135 | * |
| 139 | 136 | * @signature a -> (* -> a) |
| 140 | - * @param mixed $value |
|
| 141 | 137 | * @return callable |
| 142 | 138 | */ |
| 143 | 139 | function give() { |
@@ -166,8 +162,7 @@ discard block |
||
| 166 | 162 | * ``` |
| 167 | 163 | * |
| 168 | 164 | * @signature ((a -> Boolean), ..., (a -> Boolean)) -> (a -> Boolean) |
| 169 | - * @param callable $predicates... |
|
| 170 | - * @return callable |
|
| 165 | + * @return \Closure |
|
| 171 | 166 | */ |
| 172 | 167 | function all() { |
| 173 | 168 | $predicates = func_get_args(); |
@@ -198,8 +193,7 @@ discard block |
||
| 198 | 193 | * ``` |
| 199 | 194 | * |
| 200 | 195 | * @signature ((a -> Boolean), ..., (a -> Boolean)) -> (a -> Boolean) |
| 201 | - * @param callable $predicates... |
|
| 202 | - * @return callable |
|
| 196 | + * @return \Closure |
|
| 203 | 197 | */ |
| 204 | 198 | function any() { |
| 205 | 199 | $predicates = func_get_args(); |
@@ -94,8 +94,9 @@ |
||
| 94 | 94 | */ |
| 95 | 95 | function pipe() { |
| 96 | 96 | $fns = func_get_args(); |
| 97 | - if(count($fns) < 1) |
|
| 98 | - return identity(); |
|
| 97 | + if(count($fns) < 1) { |
|
| 98 | + return identity(); |
|
| 99 | + } |
|
| 99 | 100 | return curry(function () use ($fns) { |
| 100 | 101 | $result = _apply(array_shift($fns), func_get_args()); |
| 101 | 102 | foreach ($fns as $fn) { |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * @param callable $fn |
| 86 | 86 | * @param int $argsCount |
| 87 | 87 | * @param array $boundArgs |
| 88 | - * @return callable |
|
| 88 | + * @return \Closure |
|
| 89 | 89 | */ |
| 90 | 90 | function _curried_function($fn, $argsCount, $boundArgs = []) { |
| 91 | 91 | return function() use($fn, $argsCount, $boundArgs) { |
@@ -65,8 +65,9 @@ discard block |
||
| 65 | 65 | $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) { |
| 66 | 66 | $currentBoundArgsCount = count($currentBoundArgs); |
| 67 | 67 | $placeholderPosition = 0; |
| 68 | - while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 69 | - $placeholderPosition ++; |
|
| 68 | + while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) { |
|
| 69 | + $placeholderPosition ++; |
|
| 70 | + } |
|
| 70 | 71 | if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) { |
| 71 | 72 | $currentBoundArgs[] = $arg; |
| 72 | 73 | } else { // There is a placeholder and number of bound args >= $fnArgsCount |
@@ -92,8 +93,9 @@ discard block |
||
| 92 | 93 | $boundArgs = _merge_args($argsCount, $boundArgs, func_get_args()); |
| 93 | 94 | $numberOfPlaceholders = count(array_filter($boundArgs, _f('_is_placeholder'))); |
| 94 | 95 | $numberOfGivenArgs = count($boundArgs) - $numberOfPlaceholders; |
| 95 | - if ($numberOfGivenArgs >= $argsCount) |
|
| 96 | - return call_user_func_array($fn, $boundArgs); |
|
| 96 | + if ($numberOfGivenArgs >= $argsCount) { |
|
| 97 | + return call_user_func_array($fn, $boundArgs); |
|
| 98 | + } |
|
| 97 | 99 | return _curried_function($fn, $argsCount, $boundArgs); |
| 98 | 100 | }; |
| 99 | 101 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * Returns supported types in signatures. |
| 41 | 41 | * |
| 42 | 42 | * @signature List |
| 43 | - * @return array |
|
| 43 | + * @return string[] |
|
| 44 | 44 | */ |
| 45 | 45 | function _stream_types() { |
| 46 | 46 | return [ |
@@ -126,7 +126,6 @@ discard block |
||
| 126 | 126 | * @signature String -> String -> Maybe(Function) -> Operation |
| 127 | 127 | * @param string $name |
| 128 | 128 | * @param string $signature |
| 129 | - * @param callable $fn |
|
| 130 | 129 | * @return array |
| 131 | 130 | */ |
| 132 | 131 | function _stream_operation($name, $signature, $callable = null) { |
@@ -190,8 +189,6 @@ discard block |
||
| 190 | 189 | * F\_stream_ensure_type('List -> Bar', 'Bar'); // throws "Stream: invalid signature 'List -> Bar' it should follow the syntax 'TypeArg1 -> TypeArg2 -> ... -> ReturnType' and types to use are Boolean, Number, String, Resource, Function, List, Array, Object, Any" |
| 191 | 190 | * ``` |
| 192 | 191 | * @signature String -> String -> String |
| 193 | - * @param string $signature |
|
| 194 | - * @param string $type |
|
| 195 | 192 | * @return string |
| 196 | 193 | */ |
| 197 | 194 | function _stream_ensure_type() { |
@@ -491,8 +488,6 @@ discard block |
||
| 491 | 488 | * ``` |
| 492 | 489 | * |
| 493 | 490 | * @signature [String] -> Operation -> Boolean |
| 494 | - * @param array $argsTypes |
|
| 495 | - * @param array $operation |
|
| 496 | 491 | * @return bool |
| 497 | 492 | */ |
| 498 | 493 | function _stream_operation_is_applicable() { |
@@ -131,8 +131,9 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function _stream_operation($name, $signature, $callable = null) { |
| 133 | 133 | $callable = $callable ?: $name; |
| 134 | - if (!is_callable($callable)) |
|
| 135 | - _stream_throw_error('unknown-callable', $callable); |
|
| 134 | + if (!is_callable($callable)) { |
|
| 135 | + _stream_throw_error('unknown-callable', $callable); |
|
| 136 | + } |
|
| 136 | 137 | |
| 137 | 138 | return [ |
| 138 | 139 | 'name' => $name, |
@@ -163,8 +164,9 @@ discard block |
||
| 163 | 164 | // Assuming $text = 'Number|List -> Number -> String|Array -> Number' |
| 164 | 165 | $parts = map(pipe(split('|'), map(pipe('trim', _stream_ensure_type($text)))), split('->', $text)); |
| 165 | 166 | // $parts = [['Number', 'List'], ['Number'], ['String', 'Array'], ['Number']] |
| 166 | - if (length($parts) < 2) |
|
| 167 | - _stream_throw_error('invalid-signature', $text); |
|
| 167 | + if (length($parts) < 2) { |
|
| 168 | + _stream_throw_error('invalid-signature', $text); |
|
| 169 | + } |
|
| 168 | 170 | |
| 169 | 171 | return reduce(function($result, $part){ |
| 170 | 172 | return chain(function($item) use($result){ |
@@ -196,8 +198,9 @@ discard block |
||
| 196 | 198 | */ |
| 197 | 199 | function _stream_ensure_type() { |
| 198 | 200 | $ensureType = function($signature, $type) { |
| 199 | - if (! contains($type, _stream_types())) |
|
| 200 | - _stream_throw_error('invalid-signature', $signature); |
|
| 201 | + if (! contains($type, _stream_types())) { |
|
| 202 | + _stream_throw_error('invalid-signature', $signature); |
|
| 203 | + } |
|
| 201 | 204 | return $type; |
| 202 | 205 | }; |
| 203 | 206 | return apply(curry($ensureType), func_get_args()); |
@@ -553,8 +556,9 @@ discard block |
||
| 553 | 556 | * @return array |
| 554 | 557 | */ |
| 555 | 558 | function _stream_resolve($stream) { |
| 556 | - if (get('resolved', $stream)) |
|
| 557 | - return $stream; |
|
| 559 | + if (get('resolved', $stream)) { |
|
| 560 | + return $stream; |
|
| 561 | + } |
|
| 558 | 562 | $transformations = get('transformations', $stream); |
| 559 | 563 | $transformation = head($transformations); |
| 560 | 564 | if (null === $transformation) { |
@@ -14,8 +14,6 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @stream |
| 16 | 16 | * @signature (a -> b) -> [a] -> [b] |
| 17 | - * @param callable $fn |
|
| 18 | - * @param array $list |
|
| 19 | 17 | * @return array |
| 20 | 18 | */ |
| 21 | 19 | function map() { |
@@ -37,8 +35,6 @@ discard block |
||
| 37 | 35 | * |
| 38 | 36 | * @stream |
| 39 | 37 | * @signature (a -> [b]) -> [a] -> [b] |
| 40 | - * @param callable $fn |
|
| 41 | - * @param array $list |
|
| 42 | 38 | * @return array |
| 43 | 39 | */ |
| 44 | 40 | function chain() { |
@@ -60,8 +56,6 @@ discard block |
||
| 60 | 56 | * ``` |
| 61 | 57 | * @stream |
| 62 | 58 | * @signature (a -> Boolean) -> [a] -> [a] |
| 63 | - * @param callable $fn |
|
| 64 | - * @param array $list |
|
| 65 | 59 | * @return array |
| 66 | 60 | */ |
| 67 | 61 | function filter() { |
@@ -84,9 +78,6 @@ discard block |
||
| 84 | 78 | * |
| 85 | 79 | * @stream |
| 86 | 80 | * @signature (* -> a -> *) -> * -> [a] -> * |
| 87 | - * @param callable $fn |
|
| 88 | - * @param mixed $initial |
|
| 89 | - * @param array $list |
|
| 90 | 81 | * @return array |
| 91 | 82 | */ |
| 92 | 83 | function reduce() { |
@@ -112,8 +103,6 @@ discard block |
||
| 112 | 103 | * |
| 113 | 104 | * @stream |
| 114 | 105 | * @signature (a -> *) -> [a] -> [a] |
| 115 | - * @param callable $fn |
|
| 116 | - * @param array $list |
|
| 117 | 106 | * @return array |
| 118 | 107 | */ |
| 119 | 108 | function each() { |
@@ -140,7 +129,6 @@ discard block |
||
| 140 | 129 | * @stream |
| 141 | 130 | * @signature [a] -> a |
| 142 | 131 | * @signature String -> String |
| 143 | - * @param array|string $list |
|
| 144 | 132 | * @return mixed |
| 145 | 133 | */ |
| 146 | 134 | function head() { |
@@ -168,7 +156,6 @@ discard block |
||
| 168 | 156 | * @stream |
| 169 | 157 | * @signature [a] -> a |
| 170 | 158 | * @signature String -> String |
| 171 | - * @param array|string $list |
|
| 172 | 159 | * @return mixed |
| 173 | 160 | */ |
| 174 | 161 | function last () { |
@@ -197,7 +184,6 @@ discard block |
||
| 197 | 184 | * @stream |
| 198 | 185 | * @signature [a] -> a |
| 199 | 186 | * @signature String -> String |
| 200 | - * @param array|string $list |
|
| 201 | 187 | * @return array |
| 202 | 188 | */ |
| 203 | 189 | function init () { |
@@ -228,7 +214,6 @@ discard block |
||
| 228 | 214 | * @stream |
| 229 | 215 | * @signature [a] -> a |
| 230 | 216 | * @signature String -> String |
| 231 | - * @param array|string $list |
|
| 232 | 217 | * @return array |
| 233 | 218 | */ |
| 234 | 219 | function tail () { |
@@ -256,7 +241,6 @@ discard block |
||
| 256 | 241 | * @stream |
| 257 | 242 | * @signature [a] -> [a] |
| 258 | 243 | * @signature String -> String |
| 259 | - * @param array|string $list |
|
| 260 | 244 | * @return array |
| 261 | 245 | */ |
| 262 | 246 | function reverse () { |
@@ -280,7 +264,6 @@ discard block |
||
| 280 | 264 | * @stream |
| 281 | 265 | * @signature [a] -> Number |
| 282 | 266 | * @signature String -> Number |
| 283 | - * @param array|string $list |
|
| 284 | 267 | * @return int |
| 285 | 268 | */ |
| 286 | 269 | function length() { |
@@ -304,8 +287,6 @@ discard block |
||
| 304 | 287 | * |
| 305 | 288 | * @stream |
| 306 | 289 | * @signature (a -> Boolean) -> [a] -> Boolean |
| 307 | - * @param callable $predicate |
|
| 308 | - * @param array $list |
|
| 309 | 290 | * @return bool |
| 310 | 291 | */ |
| 311 | 292 | function allSatisfies() { |
@@ -327,8 +308,6 @@ discard block |
||
| 327 | 308 | * |
| 328 | 309 | * @stream |
| 329 | 310 | * @signature (a -> Boolean) -> [a] -> Boolean |
| 330 | - * @param callable $predicate |
|
| 331 | - * @param array $list |
|
| 332 | 311 | * @return bool |
| 333 | 312 | */ |
| 334 | 313 | function anySatisfies() { |
@@ -350,8 +329,6 @@ discard block |
||
| 350 | 329 | * @stream |
| 351 | 330 | * @signature [*] -> [*] -> [*] |
| 352 | 331 | * @signature String -> String -> String |
| 353 | - * @param array $list1 |
|
| 354 | - * @param array $list2 |
|
| 355 | 332 | * @return array |
| 356 | 333 | */ |
| 357 | 334 | function concat() { |
@@ -376,7 +353,6 @@ discard block |
||
| 376 | 353 | * |
| 377 | 354 | * @stream |
| 378 | 355 | * @signature [[a]] -> [a] |
| 379 | - * @param array $lists |
|
| 380 | 356 | * @return array |
| 381 | 357 | */ |
| 382 | 358 | function concatAll() { |
@@ -404,9 +380,6 @@ discard block |
||
| 404 | 380 | * @stream |
| 405 | 381 | * @signature Number -> a -> [a] -> [a] |
| 406 | 382 | * @signature Number -> String -> String -> String |
| 407 | - * @param int $position |
|
| 408 | - * @param mixed $item |
|
| 409 | - * @param array $list |
|
| 410 | 383 | * @return array |
| 411 | 384 | */ |
| 412 | 385 | function insert() { |
@@ -434,9 +407,6 @@ discard block |
||
| 434 | 407 | * @stream |
| 435 | 408 | * @signature Number -> [a] -> [a] -> [a] |
| 436 | 409 | * @signature Number -> String -> String -> String |
| 437 | - * @param int $position |
|
| 438 | - * @param mixed $items |
|
| 439 | - * @param array $list |
|
| 440 | 410 | * @return array |
| 441 | 411 | */ |
| 442 | 412 | function insertAll() { |
@@ -465,8 +435,6 @@ discard block |
||
| 465 | 435 | * @stream |
| 466 | 436 | * @signature * -> [*] -> [*] |
| 467 | 437 | * @signature String -> String -> String |
| 468 | - * @param mixed $item |
|
| 469 | - * @param array $list |
|
| 470 | 438 | * @return array |
| 471 | 439 | */ |
| 472 | 440 | function append() { |
@@ -489,8 +457,6 @@ discard block |
||
| 489 | 457 | * @stream |
| 490 | 458 | * @signature a -> [a] -> [a] |
| 491 | 459 | * @signature String -> String -> String |
| 492 | - * @param mixed $item |
|
| 493 | - * @param array $list |
|
| 494 | 460 | * @return array |
| 495 | 461 | */ |
| 496 | 462 | function prepend() { |
@@ -513,8 +479,6 @@ discard block |
||
| 513 | 479 | * @stream |
| 514 | 480 | * @signature Number -> [a] -> [a] |
| 515 | 481 | * @signature Number -> String -> String |
| 516 | - * @param int $count |
|
| 517 | - * @param array $list |
|
| 518 | 482 | * @return array |
| 519 | 483 | */ |
| 520 | 484 | function take() { |
@@ -547,8 +511,6 @@ discard block |
||
| 547 | 511 | * |
| 548 | 512 | * @stream |
| 549 | 513 | * @signature (a -> Boolean) -> [a] -> [a] |
| 550 | - * @param callable $predicate |
|
| 551 | - * @param array $list |
|
| 552 | 514 | * @return array |
| 553 | 515 | */ |
| 554 | 516 | function takeWhile() { |
@@ -574,8 +536,6 @@ discard block |
||
| 574 | 536 | * |
| 575 | 537 | * @stream |
| 576 | 538 | * @signature (a -> Boolean) -> [a] -> [a] |
| 577 | - * @param callable $predicate |
|
| 578 | - * @param array $list |
|
| 579 | 539 | * @return array |
| 580 | 540 | */ |
| 581 | 541 | function takeLastWhile() { |
@@ -602,8 +562,6 @@ discard block |
||
| 602 | 562 | * |
| 603 | 563 | * @stream |
| 604 | 564 | * @signature (a -> Boolean) -> [a] -> [a] |
| 605 | - * @param callable $predicate |
|
| 606 | - * @param array $list |
|
| 607 | 565 | * @return array |
| 608 | 566 | */ |
| 609 | 567 | function takeUntil() { |
@@ -625,8 +583,6 @@ discard block |
||
| 625 | 583 | * |
| 626 | 584 | * @stream |
| 627 | 585 | * @signature (a -> Boolean) -> [a] -> [a] |
| 628 | - * @param callable $predicate |
|
| 629 | - * @param array $list |
|
| 630 | 586 | * @return array |
| 631 | 587 | */ |
| 632 | 588 | function takeLastUntil() { |
@@ -654,8 +610,6 @@ discard block |
||
| 654 | 610 | * @stream |
| 655 | 611 | * @signature Number -> [a] -> [a] |
| 656 | 612 | * @signature Number -> String -> String |
| 657 | - * @param int $count |
|
| 658 | - * @param array $list |
|
| 659 | 613 | * @return array |
| 660 | 614 | */ |
| 661 | 615 | function remove() { |
@@ -683,8 +637,6 @@ discard block |
||
| 683 | 637 | * |
| 684 | 638 | * @stream |
| 685 | 639 | * @signature (a -> Boolean) -> [a] -> [a] |
| 686 | - * @param callable $predicate |
|
| 687 | - * @param array $list |
|
| 688 | 640 | * @return array |
| 689 | 641 | */ |
| 690 | 642 | function removeWhile() { |
@@ -706,8 +658,6 @@ discard block |
||
| 706 | 658 | * |
| 707 | 659 | * @stream |
| 708 | 660 | * @signature (a -> Boolean) -> [a] -> [a] |
| 709 | - * @param callable $predicate |
|
| 710 | - * @param array $list |
|
| 711 | 661 | * @return array |
| 712 | 662 | */ |
| 713 | 663 | function removeLastWhile() { |
@@ -731,8 +681,6 @@ discard block |
||
| 731 | 681 | * |
| 732 | 682 | * @stream |
| 733 | 683 | * @signature (a -> Boolean) -> [a] -> [a] |
| 734 | - * @param callable $predicate |
|
| 735 | - * @param array $list |
|
| 736 | 684 | * @return array |
| 737 | 685 | */ |
| 738 | 686 | function removeUntil() { |
@@ -755,8 +703,6 @@ discard block |
||
| 755 | 703 | * |
| 756 | 704 | * @stream |
| 757 | 705 | * @signature (a -> Boolean) -> [a] -> [a] |
| 758 | - * @param callable $predicate |
|
| 759 | - * @param array $list |
|
| 760 | 706 | * @return array |
| 761 | 707 | */ |
| 762 | 708 | function removeLastUntil() { |
@@ -776,7 +722,6 @@ discard block |
||
| 776 | 722 | * |
| 777 | 723 | * @stream |
| 778 | 724 | * @signature [(k, v)] -> {k: v} |
| 779 | - * @param array $pairs |
|
| 780 | 725 | * @return stdClass |
| 781 | 726 | */ |
| 782 | 727 | function fromPairs() { |
@@ -805,8 +750,6 @@ discard block |
||
| 805 | 750 | * @stream |
| 806 | 751 | * @signature Number -> [a] -> [[a]] |
| 807 | 752 | * @signature Number -> String -> [String] |
| 808 | - * @param int $size |
|
| 809 | - * @param array $list |
|
| 810 | 753 | * @return array |
| 811 | 754 | */ |
| 812 | 755 | function slices() { |
@@ -834,8 +777,6 @@ discard block |
||
| 834 | 777 | * @stream |
| 835 | 778 | * @signature a -> [a] -> Boolean |
| 836 | 779 | * @signature String -> String -> Boolean |
| 837 | - * @param mixed $item |
|
| 838 | - * @param array|string $list |
|
| 839 | 780 | * @return bool |
| 840 | 781 | */ |
| 841 | 782 | function contains() { |
@@ -859,8 +800,6 @@ discard block |
||
| 859 | 800 | * @stream |
| 860 | 801 | * @signature (a -> Boolean) -> [a] -> Maybe(Number) |
| 861 | 802 | * @signature (v -> Boolean) -> {k: v} -> Maybe(k) |
| 862 | - * @param callable $predicate |
|
| 863 | - * @param array $list |
|
| 864 | 803 | * @return mixed |
| 865 | 804 | */ |
| 866 | 805 | function findIndex() { |
@@ -888,8 +827,6 @@ discard block |
||
| 888 | 827 | * @stream |
| 889 | 828 | * @signature (a -> Boolean) -> [a] -> Maybe(Number) |
| 890 | 829 | * @signature (v -> Boolean) -> {k: v} -> Maybe(k) |
| 891 | - * @param callable $predicate |
|
| 892 | - * @param array $list |
|
| 893 | 830 | * @return mixed |
| 894 | 831 | */ |
| 895 | 832 | function findLastIndex() { |
@@ -915,8 +852,6 @@ discard block |
||
| 915 | 852 | * |
| 916 | 853 | * @stream |
| 917 | 854 | * @signature (a -> Boolean) -> [a] -> Maybe(a) |
| 918 | - * @param callable $predicate |
|
| 919 | - * @param array $list |
|
| 920 | 855 | * @return mixed |
| 921 | 856 | */ |
| 922 | 857 | function find() { |
@@ -938,8 +873,6 @@ discard block |
||
| 938 | 873 | * |
| 939 | 874 | * @stream |
| 940 | 875 | * @signature (a -> Boolean) -> [a] -> Maybe(a) |
| 941 | - * @param callable $predicate |
|
| 942 | - * @param array $list |
|
| 943 | 876 | * @return mixed |
| 944 | 877 | */ |
| 945 | 878 | function findLast() { |
@@ -970,8 +903,6 @@ discard block |
||
| 970 | 903 | * @signature a -> [a] -> Number |
| 971 | 904 | * @signature v -> {k: v} -> Maybe(k) |
| 972 | 905 | * @signature String -> String -> Number |
| 973 | - * @param mixed $item |
|
| 974 | - * @param array $list |
|
| 975 | 906 | * @return int |
| 976 | 907 | */ |
| 977 | 908 | function indexOf() { |
@@ -1003,8 +934,6 @@ discard block |
||
| 1003 | 934 | * @stream |
| 1004 | 935 | * @signature a -> [a] -> Number |
| 1005 | 936 | * @signature String -> String -> Number |
| 1006 | - * @param mixed $item |
|
| 1007 | - * @param array $list |
|
| 1008 | 937 | * @return int |
| 1009 | 938 | */ |
| 1010 | 939 | function lastIndexOf() { |
@@ -1033,8 +962,6 @@ discard block |
||
| 1033 | 962 | * |
| 1034 | 963 | * @stream |
| 1035 | 964 | * @signature (a -> a -> Boolean) -> [a] -> [a] |
| 1036 | - * @param callable $areEqual |
|
| 1037 | - * @param array $list |
|
| 1038 | 965 | * @return array |
| 1039 | 966 | */ |
| 1040 | 967 | function uniqueBy() { |
@@ -1065,7 +992,6 @@ discard block |
||
| 1065 | 992 | * |
| 1066 | 993 | * @stream |
| 1067 | 994 | * @signature [a] -> [a] |
| 1068 | - * @param array $list |
|
| 1069 | 995 | * @return array |
| 1070 | 996 | */ |
| 1071 | 997 | function unique() { |
@@ -1098,8 +1024,6 @@ discard block |
||
| 1098 | 1024 | * |
| 1099 | 1025 | * @stream |
| 1100 | 1026 | * @signature (a -> String) -> [a] -> {String: a} |
| 1101 | - * @param callable $fn |
|
| 1102 | - * @param array $list |
|
| 1103 | 1027 | * @return array |
| 1104 | 1028 | */ |
| 1105 | 1029 | function groupBy() { |
@@ -1128,8 +1052,6 @@ discard block |
||
| 1128 | 1052 | * |
| 1129 | 1053 | * @stream |
| 1130 | 1054 | * @signature [a] -> [b] -> [[a,b]] |
| 1131 | - * @param array $list1 |
|
| 1132 | - * @param array $list2 |
|
| 1133 | 1055 | * @return array |
| 1134 | 1056 | */ |
| 1135 | 1057 | function pairsFrom() { |
@@ -146,8 +146,9 @@ discard block |
||
| 146 | 146 | function head() { |
| 147 | 147 | static $head = false; |
| 148 | 148 | $head = $head ?: curry(function($list) { |
| 149 | - if(is_string($list)) |
|
| 150 | - return substr($list, 0, 1); |
|
| 149 | + if(is_string($list)) { |
|
| 150 | + return substr($list, 0, 1); |
|
| 151 | + } |
|
| 151 | 152 | return (count($list) > 0) |
| 152 | 153 | ? $list[0] |
| 153 | 154 | : null; |
@@ -174,8 +175,9 @@ discard block |
||
| 174 | 175 | function last () { |
| 175 | 176 | static $last = false; |
| 176 | 177 | $last = $last ?: curry(function($list) { |
| 177 | - if(is_string($list)) |
|
| 178 | - return substr($list, -1); |
|
| 178 | + if(is_string($list)) { |
|
| 179 | + return substr($list, -1); |
|
| 180 | + } |
|
| 179 | 181 | return (count($list) > 0) |
| 180 | 182 | ? $list[count($list) - 1] |
| 181 | 183 | : null; |
@@ -203,10 +205,11 @@ discard block |
||
| 203 | 205 | function init () { |
| 204 | 206 | static $init = false; |
| 205 | 207 | $init = $init ?: curry(function($list) { |
| 206 | - if(is_string($list)) |
|
| 207 | - return (strlen($list) > 1) |
|
| 208 | + if(is_string($list)) { |
|
| 209 | + return (strlen($list) > 1) |
|
| 208 | 210 | ? substr($list, 0, strlen($list) - 1) |
| 209 | 211 | : ''; |
| 212 | + } |
|
| 210 | 213 | return (count($list) > 1) |
| 211 | 214 | ? array_slice($list, 0, count($list) - 1) |
| 212 | 215 | : []; |
@@ -234,10 +237,11 @@ discard block |
||
| 234 | 237 | function tail () { |
| 235 | 238 | static $tail = false; |
| 236 | 239 | $tail = $tail ?: curry(function($list) { |
| 237 | - if(is_string($list)) |
|
| 238 | - return (strlen($list) > 1) |
|
| 240 | + if(is_string($list)) { |
|
| 241 | + return (strlen($list) > 1) |
|
| 239 | 242 | ? substr($list, 1) |
| 240 | 243 | : ''; |
| 244 | + } |
|
| 241 | 245 | return (count($list) > 1) |
| 242 | 246 | ? array_slice($list, 1) |
| 243 | 247 | : []; |
@@ -359,8 +363,9 @@ discard block |
||
| 359 | 363 | $concat = $concat ?: curry(function($list1, $list2) { |
| 360 | 364 | $t1 = toString($list1); |
| 361 | 365 | $t2 = toString($list2); |
| 362 | - if (is_string($list1) && is_string($list2)) |
|
| 363 | - return $list1 . $list2; |
|
| 366 | + if (is_string($list1) && is_string($list2)) { |
|
| 367 | + return $list1 . $list2; |
|
| 368 | + } |
|
| 364 | 369 | return array_merge($list1, $list2); |
| 365 | 370 | }); |
| 366 | 371 | return _apply($concat, func_get_args()); |
@@ -443,10 +448,12 @@ discard block |
||
| 443 | 448 | static $insertAll = false; |
| 444 | 449 | $insertAll = $insertAll ?: curry(function($position, $items, $list) { |
| 445 | 450 | $length = length($list); |
| 446 | - if ($position < 0) |
|
| 447 | - $position = $length + $position; |
|
| 448 | - if ($position < 0) |
|
| 449 | - $position = 0; |
|
| 451 | + if ($position < 0) { |
|
| 452 | + $position = $length + $position; |
|
| 453 | + } |
|
| 454 | + if ($position < 0) { |
|
| 455 | + $position = 0; |
|
| 456 | + } |
|
| 450 | 457 | return ($position >= $length) |
| 451 | 458 | ? concat($list, $items) |
| 452 | 459 | : concatAll([take($position, $list), $items, remove($position, $list)]); |
@@ -521,8 +528,9 @@ discard block |
||
| 521 | 528 | static $take = false; |
| 522 | 529 | $take = $take ?: curry(function($count, $list) { |
| 523 | 530 | $length = length($list); |
| 524 | - if ($count > $length || $count < -$length) |
|
| 525 | - return []; |
|
| 531 | + if ($count > $length || $count < -$length) { |
|
| 532 | + return []; |
|
| 533 | + } |
|
| 526 | 534 | if(is_string($list)) { |
| 527 | 535 | return ($count >= 0) |
| 528 | 536 | ? substr($list, 0, $count) |
@@ -662,8 +670,9 @@ discard block |
||
| 662 | 670 | static $remove = false; |
| 663 | 671 | $remove = $remove ?: curry(function($count, $list) { |
| 664 | 672 | $length = length($list); |
| 665 | - if ($count > $length || $count < -$length) |
|
| 666 | - return []; |
|
| 673 | + if ($count > $length || $count < -$length) { |
|
| 674 | + return []; |
|
| 675 | + } |
|
| 667 | 676 | return ($count > 0) |
| 668 | 677 | ? take($count - $length, $list) |
| 669 | 678 | : take($count + $length, $list); |
@@ -812,10 +821,12 @@ discard block |
||
| 812 | 821 | function slices() { |
| 813 | 822 | static $slices = false; |
| 814 | 823 | $slices = $slices ?: curry(function($size, $list) { |
| 815 | - if(empty($list)) |
|
| 816 | - return is_string($list) ? '' : []; |
|
| 817 | - if(length($list) <= $size) |
|
| 818 | - return [$list]; |
|
| 824 | + if(empty($list)) { |
|
| 825 | + return is_string($list) ? '' : []; |
|
| 826 | + } |
|
| 827 | + if(length($list) <= $size) { |
|
| 828 | + return [$list]; |
|
| 829 | + } |
|
| 819 | 830 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
| 820 | 831 | }); |
| 821 | 832 | return _apply($slices, func_get_args()); |
@@ -867,8 +878,9 @@ discard block |
||
| 867 | 878 | static $findIndex = false; |
| 868 | 879 | $findIndex = $findIndex ?: curry(function($predicate, $list) { |
| 869 | 880 | foreach ($list as $key => $value) { |
| 870 | - if ($predicate($value)) |
|
| 871 | - return $key; |
|
| 881 | + if ($predicate($value)) { |
|
| 882 | + return $key; |
|
| 883 | + } |
|
| 872 | 884 | } |
| 873 | 885 | return null; |
| 874 | 886 | }); |
@@ -896,8 +908,9 @@ discard block |
||
| 896 | 908 | static $findLastIndex = false; |
| 897 | 909 | $findLastIndex = $findLastIndex ?: curry(function($predicate, $list) { |
| 898 | 910 | foreach (reverse(toPairs($list)) as $pair) { |
| 899 | - if($predicate($pair[1])) |
|
| 900 | - return $pair[0]; |
|
| 911 | + if($predicate($pair[1])) { |
|
| 912 | + return $pair[0]; |
|
| 913 | + } |
|
| 901 | 914 | } |
| 902 | 915 | return null; |
| 903 | 916 | }); |
@@ -1107,8 +1120,9 @@ discard block |
||
| 1107 | 1120 | $groupBy = $groupBy ?: curry(function($fn, $list) { |
| 1108 | 1121 | return reduce(function($result, $item) use($fn) { |
| 1109 | 1122 | $index = $fn($item); |
| 1110 | - if (! isset($result[$index])) |
|
| 1111 | - $result[$index] = []; |
|
| 1123 | + if (! isset($result[$index])) { |
|
| 1124 | + $result[$index] = []; |
|
| 1125 | + } |
|
| 1112 | 1126 | $result[$index][] = $item; |
| 1113 | 1127 | return $result; |
| 1114 | 1128 | }, [], $list); |
@@ -1137,8 +1151,9 @@ discard block |
||
| 1137 | 1151 | $pairsFrom = $pairsFrom ?: curry(function($list1, $list2) { |
| 1138 | 1152 | $length1 = length($list1); |
| 1139 | 1153 | $length2 = length($list2); |
| 1140 | - if (0 == $length1 || 0 == $length2) |
|
| 1141 | - return []; |
|
| 1154 | + if (0 == $length1 || 0 == $length2) { |
|
| 1155 | + return []; |
|
| 1156 | + } |
|
| 1142 | 1157 | $list1 = values($list1); |
| 1143 | 1158 | $list2 = values($list2); |
| 1144 | 1159 | return map(function($index) use($list1, $list2) { |