@@ -3,8 +3,6 @@ |
||
| 3 | 3 | * This file contains functions dealing with functions. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -use Tarsana\Functional\Exceptions\InvalidArgument; |
|
| 7 | - |
|
| 8 | 6 | /** |
| 9 | 7 | * Adds the `Tarsana\Functional\` namespace to a function name. |
| 10 | 8 | * This is useful to pass non-curried functions as parameter. |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param mixed $something |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | -function toString () { |
|
| 85 | +function toString() { |
|
| 86 | 86 | $toString = function($something) { |
| 87 | 87 | switch (type($something)) { |
| 88 | 88 | case 'String': |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | return $something->__toString(); |
| 106 | 106 | case 'Object': |
| 107 | 107 | case 'Array': |
| 108 | - return '{' . join(', ', map(function($pair){ |
|
| 109 | - return $pair[0].': '. toString($pair[1]); |
|
| 108 | + return '{' . join(', ', map(function($pair) { |
|
| 109 | + return $pair[0] . ': ' . toString($pair[1]); |
|
| 110 | 110 | }, toPairs($something))) . '}'; |
| 111 | 111 | default: |
| 112 | - return '['.type($something).']'; |
|
| 112 | + return '[' . type($something) . ']'; |
|
| 113 | 113 | } |
| 114 | 114 | }; |
| 115 | 115 | return apply(curry($toString), func_get_args()); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @return int|float |
| 17 | 17 | */ |
| 18 | 18 | function plus() { |
| 19 | - $plus = curry(function($x, $y){ |
|
| 19 | + $plus = curry(function($x, $y) { |
|
| 20 | 20 | return $x + $y; |
| 21 | 21 | }); |
| 22 | 22 | return apply($plus, func_get_args()); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return int|float |
| 35 | 35 | */ |
| 36 | 36 | function minus() { |
| 37 | - $minus = curry(function($x, $y){ |
|
| 37 | + $minus = curry(function($x, $y) { |
|
| 38 | 38 | return $x - $y; |
| 39 | 39 | }); |
| 40 | 40 | return apply($minus, func_get_args()); |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * @return int|float |
| 53 | 53 | */ |
| 54 | 54 | function negate() { |
| 55 | - return apply(curry(function($x){ |
|
| 56 | - return -$x; |
|
| 55 | + return apply(curry(function($x) { |
|
| 56 | + return - $x; |
|
| 57 | 57 | }), func_get_args()); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @return int|float |
| 71 | 71 | */ |
| 72 | 72 | function multiply() { |
| 73 | - $multiply = curry(function($x, $y){ |
|
| 73 | + $multiply = curry(function($x, $y) { |
|
| 74 | 74 | return $y * $x; |
| 75 | 75 | }); |
| 76 | 76 | return apply($multiply, func_get_args()); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @return int|float |
| 89 | 89 | */ |
| 90 | 90 | function divide() { |
| 91 | - $divide = curry(function($x, $y){ |
|
| 91 | + $divide = curry(function($x, $y) { |
|
| 92 | 92 | return $x / $y; |
| 93 | 93 | }); |
| 94 | 94 | return apply($divide, func_get_args()); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return int|float |
| 107 | 107 | */ |
| 108 | 108 | function modulo() { |
| 109 | - $modulo = curry(function($x, $y){ |
|
| 109 | + $modulo = curry(function($x, $y) { |
|
| 110 | 110 | return $x % $y; |
| 111 | 111 | }); |
| 112 | 112 | return apply($modulo, func_get_args()); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @return int|float |
| 125 | 125 | */ |
| 126 | 126 | function sum() { |
| 127 | - return apply(curry(function($numbers){ |
|
| 127 | + return apply(curry(function($numbers) { |
|
| 128 | 128 | return reduce(plus(), 0, $numbers); |
| 129 | 129 | }), func_get_args()); |
| 130 | 130 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @return int|float |
| 142 | 142 | */ |
| 143 | 143 | function product() { |
| 144 | - return apply(curry(function($numbers){ |
|
| 144 | + return apply(curry(function($numbers) { |
|
| 145 | 145 | return reduce(multiply(), 1, $numbers); |
| 146 | 146 | }), func_get_args()); |
| 147 | 147 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function join() { |
| 35 | - return apply(curry(function($glue, $pieces){ |
|
| 35 | + return apply(curry(function($glue, $pieces) { |
|
| 36 | 36 | return implode($glue, $pieces); |
| 37 | 37 | }), func_get_args()); |
| 38 | 38 | } |
@@ -306,8 +306,7 @@ discard block |
||
| 306 | 306 | $updateCountAt = curry(function($item, $counts, $index) use($openings, $closings) { |
| 307 | 307 | $count = occurences(__(), $item); |
| 308 | 308 | return ($openings[$index] == $closings[$index]) ? |
| 309 | - ($counts[$index] + $count($openings[$index])) % 2 : |
|
| 310 | - $counts[$index] + $count($openings[$index]) - $count($closings[$index]); |
|
| 309 | + ($counts[$index] + $count($openings[$index])) % 2 : $counts[$index] + $count($openings[$index]) - $count($closings[$index]); |
|
| 311 | 310 | }); |
| 312 | 311 | // Updates counts for all surrenders |
| 313 | 312 | $updateCounts = curry(function($item, $counts) use($indexes, $updateCountAt) { |