@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class AppendTest extends TestCase |
| 8 | 8 | { |
| 9 | - public function testAppend() |
|
| 10 | - { |
|
| 9 | + public function testAppend() |
|
| 10 | + { |
|
| 11 | 11 | $result = append(3)([1, 2]); |
| 12 | 12 | $this->assertEquals([1, 2, 3], $result); |
| 13 | - } |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function testAppendWithoutAutoCurry() |
|
| 16 | - { |
|
| 15 | + public function testAppendWithoutAutoCurry() |
|
| 16 | + { |
|
| 17 | 17 | $result = append(3, [1, 2]); |
| 18 | 18 | $this->assertEquals([1, 2, 3], $result); |
| 19 | - } |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -6,12 +6,12 @@ |
||
| 6 | 6 | |
| 7 | 7 | class SubtractTest extends TestCase |
| 8 | 8 | { |
| 9 | - public function testDivide() |
|
| 10 | - { |
|
| 9 | + public function testDivide() |
|
| 10 | + { |
|
| 11 | 11 | $firstValue = 50; |
| 12 | 12 | $secondValue = 10; |
| 13 | 13 | $expectedResult = 40; |
| 14 | 14 | $actualResult = subtract($firstValue)($secondValue); |
| 15 | 15 | $this->assertEquals($expectedResult, $actualResult); |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class PrependTest extends TestCase |
| 8 | 8 | { |
| 9 | - public function testAppend() |
|
| 10 | - { |
|
| 9 | + public function testAppend() |
|
| 10 | + { |
|
| 11 | 11 | $result = prepend(1)([2, 3]); |
| 12 | 12 | $this->assertEquals([1, 2, 3], $result); |
| 13 | - } |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function testAppendWithoutAutoCurry() |
|
| 16 | - { |
|
| 15 | + public function testAppendWithoutAutoCurry() |
|
| 16 | + { |
|
| 17 | 17 | $result = prepend(1, [2, 3]); |
| 18 | 18 | $this->assertEquals([1, 2, 3], $result); |
| 19 | - } |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -9,12 +9,12 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function add() |
| 11 | 11 | { |
| 12 | - $add = function ($firstValue, $secondValue) { |
|
| 12 | + $add = function ($firstValue, $secondValue) { |
|
| 13 | 13 | return $firstValue + $secondValue; |
| 14 | - }; |
|
| 15 | - $arguments = func_get_args(); |
|
| 16 | - $curried = curryN($add, 2); |
|
| 17 | - return call_user_func_array($curried, $arguments); |
|
| 14 | + }; |
|
| 15 | + $arguments = func_get_args(); |
|
| 16 | + $curried = curryN($add, 2); |
|
| 17 | + return call_user_func_array($curried, $arguments); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function divide() |
| 27 | 27 | { |
| 28 | - $divide = function ($firstValue, $secondValue) { |
|
| 28 | + $divide = function ($firstValue, $secondValue) { |
|
| 29 | 29 | return $firstValue / $secondValue; |
| 30 | - }; |
|
| 31 | - $arguments = func_get_args(); |
|
| 32 | - $curried = curryN($divide, 2); |
|
| 33 | - return call_user_func_array($curried, $arguments); |
|
| 30 | + }; |
|
| 31 | + $arguments = func_get_args(); |
|
| 32 | + $curried = curryN($divide, 2); |
|
| 33 | + return call_user_func_array($curried, $arguments); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function multiply() |
| 43 | 43 | { |
| 44 | - $multiply = function ($firstValue, $secondValue) { |
|
| 44 | + $multiply = function ($firstValue, $secondValue) { |
|
| 45 | 45 | return $firstValue * $secondValue; |
| 46 | - }; |
|
| 47 | - $arguments = func_get_args(); |
|
| 48 | - $curried = curryN($multiply, 2); |
|
| 49 | - return call_user_func_array($curried, $arguments); |
|
| 46 | + }; |
|
| 47 | + $arguments = func_get_args(); |
|
| 48 | + $curried = curryN($multiply, 2); |
|
| 49 | + return call_user_func_array($curried, $arguments); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -57,10 +57,10 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | function subtract() |
| 59 | 59 | { |
| 60 | - $subtract = function ($firstValue, $secondValue) { |
|
| 60 | + $subtract = function ($firstValue, $secondValue) { |
|
| 61 | 61 | return $firstValue - $secondValue; |
| 62 | - }; |
|
| 63 | - $arguments = func_get_args(); |
|
| 64 | - $curried = curryN($subtract, 2); |
|
| 65 | - return call_user_func_array($curried, $arguments); |
|
| 62 | + }; |
|
| 63 | + $arguments = func_get_args(); |
|
| 64 | + $curried = curryN($subtract, 2); |
|
| 65 | + return call_user_func_array($curried, $arguments); |
|
| 66 | 66 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function add() |
| 11 | 11 | { |
| 12 | - $add = function ($firstValue, $secondValue) { |
|
| 12 | + $add = function($firstValue, $secondValue) { |
|
| 13 | 13 | return $firstValue + $secondValue; |
| 14 | 14 | }; |
| 15 | 15 | $arguments = func_get_args(); |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function divide() |
| 27 | 27 | { |
| 28 | - $divide = function ($firstValue, $secondValue) { |
|
| 28 | + $divide = function($firstValue, $secondValue) { |
|
| 29 | 29 | return $firstValue / $secondValue; |
| 30 | 30 | }; |
| 31 | 31 | $arguments = func_get_args(); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function multiply() |
| 43 | 43 | { |
| 44 | - $multiply = function ($firstValue, $secondValue) { |
|
| 44 | + $multiply = function($firstValue, $secondValue) { |
|
| 45 | 45 | return $firstValue * $secondValue; |
| 46 | 46 | }; |
| 47 | 47 | $arguments = func_get_args(); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | function subtract() |
| 59 | 59 | { |
| 60 | - $subtract = function ($firstValue, $secondValue) { |
|
| 60 | + $subtract = function($firstValue, $secondValue) { |
|
| 61 | 61 | return $firstValue - $secondValue; |
| 62 | 62 | }; |
| 63 | 63 | $arguments = func_get_args(); |
@@ -7,12 +7,12 @@ |
||
| 7 | 7 | |
| 8 | 8 | class PartialTest extends TestCase |
| 9 | 9 | { |
| 10 | - public function testPartial() |
|
| 11 | - { |
|
| 10 | + public function testPartial() |
|
| 11 | + { |
|
| 12 | 12 | $double = partial(multiply(), [2]); |
| 13 | 13 | $arg = 10; |
| 14 | 14 | $expectedResult = 20; |
| 15 | 15 | $actualResult = $double($arg); |
| 16 | 16 | $this->assertEquals($expectedResult, $actualResult); |
| 17 | - } |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -7,12 +7,12 @@ |
||
| 7 | 7 | |
| 8 | 8 | class PartialRightTest extends TestCase |
| 9 | 9 | { |
| 10 | - public function testPartial() |
|
| 11 | - { |
|
| 10 | + public function testPartial() |
|
| 11 | + { |
|
| 12 | 12 | $double = partialRight(divide(), [2]); |
| 13 | 13 | $arg = 10; |
| 14 | 14 | $expectedResult = 5; |
| 15 | 15 | $actualResult = $double($arg); |
| 16 | 16 | $this->assertEquals($expectedResult, $actualResult); |
| 17 | - } |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -7,13 +7,13 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ApplyTest extends TestCase |
| 9 | 9 | { |
| 10 | - public function testApply() |
|
| 11 | - { |
|
| 10 | + public function testApply() |
|
| 11 | + { |
|
| 12 | 12 | $add = add(); |
| 13 | 13 | $firstArg = 1; |
| 14 | 14 | $secondArg = 2; |
| 15 | 15 | $expectedResult = 3; |
| 16 | 16 | $actualResult = apply($add)([$firstArg, $secondArg]); |
| 17 | 17 | $this->assertEquals($expectedResult, $actualResult); |
| 18 | - } |
|
| 18 | + } |
|
| 19 | 19 | } |
@@ -7,23 +7,23 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CallTest extends TestCase |
| 9 | 9 | { |
| 10 | - public function testCallWithCurrying() |
|
| 11 | - { |
|
| 10 | + public function testCallWithCurrying() |
|
| 11 | + { |
|
| 12 | 12 | $add = add(); |
| 13 | 13 | $firstArg = 1; |
| 14 | 14 | $secondArg = 2; |
| 15 | 15 | $expectedResult = 3; |
| 16 | 16 | $actualResult = call()($add)($firstArg, $secondArg); |
| 17 | 17 | $this->assertEquals($expectedResult, $actualResult); |
| 18 | - } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function testCallWithoutCurrying() |
|
| 21 | - { |
|
| 20 | + public function testCallWithoutCurrying() |
|
| 21 | + { |
|
| 22 | 22 | $add = add(); |
| 23 | 23 | $firstArg = 1; |
| 24 | 24 | $secondArg = 2; |
| 25 | 25 | $expectedResult = 3; |
| 26 | 26 | $actualResult = call($add, $firstArg, $secondArg); |
| 27 | 27 | $this->assertEquals($expectedResult, $actualResult); |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -7,14 +7,14 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | function always() |
| 9 | 9 | { |
| 10 | - $always = function ($data) { |
|
| 10 | + $always = function ($data) { |
|
| 11 | 11 | return function () use ($data) { |
| 12 | - return $data; |
|
| 12 | + return $data; |
|
| 13 | 13 | }; |
| 14 | - }; |
|
| 15 | - $arguments = func_get_args(); |
|
| 16 | - $curried = curryN($always, 1); |
|
| 17 | - return call_user_func_array($curried, $arguments); |
|
| 14 | + }; |
|
| 15 | + $arguments = func_get_args(); |
|
| 16 | + $curried = curryN($always, 1); |
|
| 17 | + return call_user_func_array($curried, $arguments); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function apply() |
| 26 | 26 | { |
| 27 | - $apply = function (callable $fn, array $args) { |
|
| 27 | + $apply = function (callable $fn, array $args) { |
|
| 28 | 28 | return call_user_func_array($fn, $args); |
| 29 | - }; |
|
| 30 | - $arguments = func_get_args(); |
|
| 31 | - $curried = curryN($apply, 2); |
|
| 32 | - return call_user_func_array($curried, $arguments); |
|
| 29 | + }; |
|
| 30 | + $arguments = func_get_args(); |
|
| 31 | + $curried = curryN($apply, 2); |
|
| 32 | + return call_user_func_array($curried, $arguments); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | function call() |
| 41 | 41 | { |
| 42 | - $arguments = func_get_args(); |
|
| 43 | - $length = count($arguments); |
|
| 44 | - switch ($length) { |
|
| 42 | + $arguments = func_get_args(); |
|
| 43 | + $length = count($arguments); |
|
| 44 | + switch ($length) { |
|
| 45 | 45 | case 0: |
| 46 | 46 | return __FUNCTION__; |
| 47 | 47 | case 1: |
| 48 | 48 | $fn = $arguments[0]; |
| 49 | - return function (...$arguments) use ($fn) { |
|
| 49 | + return function (...$arguments) use ($fn) { |
|
| 50 | 50 | return call_user_func_array($fn, $arguments); |
| 51 | - }; |
|
| 51 | + }; |
|
| 52 | 52 | default: |
| 53 | 53 | $fn = $arguments[0]; |
| 54 | - $arguments = dropFirst($arguments); |
|
| 55 | - return call_user_func_array($fn, $arguments); |
|
| 56 | - } |
|
| 54 | + $arguments = dropFirst($arguments); |
|
| 55 | + return call_user_func_array($fn, $arguments); |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | function compose() |
| 64 | 64 | { |
| 65 | - $arguments = array_reverse(func_get_args()); |
|
| 66 | - return call_user_func_array('Aerophant\Ramda\pipe', $arguments); |
|
| 65 | + $arguments = array_reverse(func_get_args()); |
|
| 66 | + return call_user_func_array('Aerophant\Ramda\pipe', $arguments); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -72,37 +72,37 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function construct() |
| 74 | 74 | { |
| 75 | - $construct = function ($class) { |
|
| 75 | + $construct = function ($class) { |
|
| 76 | 76 | return function () use ($class) { |
| 77 | - return new $class(); |
|
| 77 | + return new $class(); |
|
| 78 | + }; |
|
| 78 | 79 | }; |
| 79 | - }; |
|
| 80 | - $arguments = func_get_args(); |
|
| 81 | - $curried = curryN($construct, 1); |
|
| 82 | - return call_user_func_array($curried, $arguments); |
|
| 80 | + $arguments = func_get_args(); |
|
| 81 | + $curried = curryN($construct, 1); |
|
| 82 | + return call_user_func_array($curried, $arguments); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | function curryN(callable $fn, int $numberOfArguments) |
| 86 | 86 | { |
| 87 | - return function () use ($fn, $numberOfArguments) { |
|
| 87 | + return function () use ($fn, $numberOfArguments) { |
|
| 88 | 88 | $arguments = func_get_args(); |
| 89 | 89 | $length = count($arguments); |
| 90 | 90 | if ($length > $numberOfArguments) { |
| 91 | - throw new \InvalidArgumentException( |
|
| 91 | + throw new \InvalidArgumentException( |
|
| 92 | 92 | "Number of passed($length) parameters is greater than expected($numberOfArguments)" |
| 93 | - ); |
|
| 93 | + ); |
|
| 94 | 94 | } |
| 95 | 95 | // NO CURRY |
| 96 | 96 | if ($length == $numberOfArguments) { |
| 97 | - return call_user_func_array($fn, $arguments); |
|
| 97 | + return call_user_func_array($fn, $arguments); |
|
| 98 | 98 | } |
| 99 | 99 | // AUTO CURRY |
| 100 | 100 | $curriedFn = function () use ($fn, $arguments) { |
| 101 | - $curriedArguments = func_get_args(); |
|
| 102 | - return call_user_func_array($fn, array_merge($arguments, $curriedArguments)); |
|
| 101 | + $curriedArguments = func_get_args(); |
|
| 102 | + return call_user_func_array($fn, array_merge($arguments, $curriedArguments)); |
|
| 103 | 103 | }; |
| 104 | 104 | return curryN($curriedFn, $numberOfArguments - $length); |
| 105 | - }; |
|
| 105 | + }; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function partial(callable $fn, array $args) |
| 115 | 115 | { |
| 116 | - return function () use ($fn, $args) { |
|
| 116 | + return function () use ($fn, $args) { |
|
| 117 | 117 | $arguments = func_get_args(); |
| 118 | 118 | return call_user_func_array($fn, array_merge($args, $arguments)); |
| 119 | - }; |
|
| 119 | + }; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | function partialRight(callable $fn, array $args) |
| 129 | 129 | { |
| 130 | - return function () use ($fn, $args) { |
|
| 130 | + return function () use ($fn, $args) { |
|
| 131 | 131 | $arguments = func_get_args(); |
| 132 | 132 | return call_user_func_array($fn, array_merge($arguments, $args)); |
| 133 | - }; |
|
| 133 | + }; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,17 +139,17 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | function pipe() |
| 141 | 141 | { |
| 142 | - $arguments = func_get_args(); |
|
| 143 | - $length = count($arguments); |
|
| 144 | - if ($length === 0) { |
|
| 142 | + $arguments = func_get_args(); |
|
| 143 | + $length = count($arguments); |
|
| 144 | + if ($length === 0) { |
|
| 145 | 145 | throw new \Exception("pipe requires at least one argument"); |
| 146 | - } |
|
| 147 | - return function () use ($arguments) { |
|
| 146 | + } |
|
| 147 | + return function () use ($arguments) { |
|
| 148 | 148 | $internalArguments = func_get_args(); |
| 149 | 149 | $initialValue = call_user_func_array($arguments[0], $internalArguments); |
| 150 | 150 | $accumulator = function ($acc, $it) { |
| 151 | - return call_user_func_array($it, [$acc]); |
|
| 151 | + return call_user_func_array($it, [$acc]); |
|
| 152 | 152 | }; |
| 153 | 153 | return array_reduce(drop(0, $arguments), $accumulator, $initialValue); |
| 154 | - }; |
|
| 154 | + }; |
|
| 155 | 155 | } |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | function always() |
| 9 | 9 | { |
| 10 | - $always = function ($data) { |
|
| 11 | - return function () use ($data) { |
|
| 10 | + $always = function($data) { |
|
| 11 | + return function() use ($data) { |
|
| 12 | 12 | return $data; |
| 13 | 13 | }; |
| 14 | 14 | }; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function apply() |
| 26 | 26 | { |
| 27 | - $apply = function (callable $fn, array $args) { |
|
| 27 | + $apply = function(callable $fn, array $args) { |
|
| 28 | 28 | return call_user_func_array($fn, $args); |
| 29 | 29 | }; |
| 30 | 30 | $arguments = func_get_args(); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | return __FUNCTION__; |
| 47 | 47 | case 1: |
| 48 | 48 | $fn = $arguments[0]; |
| 49 | - return function (...$arguments) use ($fn) { |
|
| 49 | + return function(...$arguments) use ($fn) { |
|
| 50 | 50 | return call_user_func_array($fn, $arguments); |
| 51 | 51 | }; |
| 52 | 52 | default: |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function construct() |
| 74 | 74 | { |
| 75 | - $construct = function ($class) { |
|
| 76 | - return function () use ($class) { |
|
| 75 | + $construct = function($class) { |
|
| 76 | + return function() use ($class) { |
|
| 77 | 77 | return new $class(); |
| 78 | 78 | }; |
| 79 | 79 | }; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | function curryN(callable $fn, int $numberOfArguments) |
| 86 | 86 | { |
| 87 | - return function () use ($fn, $numberOfArguments) { |
|
| 87 | + return function() use ($fn, $numberOfArguments) { |
|
| 88 | 88 | $arguments = func_get_args(); |
| 89 | 89 | $length = count($arguments); |
| 90 | 90 | if ($length > $numberOfArguments) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | return call_user_func_array($fn, $arguments); |
| 98 | 98 | } |
| 99 | 99 | // AUTO CURRY |
| 100 | - $curriedFn = function () use ($fn, $arguments) { |
|
| 100 | + $curriedFn = function() use ($fn, $arguments) { |
|
| 101 | 101 | $curriedArguments = func_get_args(); |
| 102 | 102 | return call_user_func_array($fn, array_merge($arguments, $curriedArguments)); |
| 103 | 103 | }; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function partial(callable $fn, array $args) |
| 115 | 115 | { |
| 116 | - return function () use ($fn, $args) { |
|
| 116 | + return function() use ($fn, $args) { |
|
| 117 | 117 | $arguments = func_get_args(); |
| 118 | 118 | return call_user_func_array($fn, array_merge($args, $arguments)); |
| 119 | 119 | }; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | function partialRight(callable $fn, array $args) |
| 129 | 129 | { |
| 130 | - return function () use ($fn, $args) { |
|
| 130 | + return function() use ($fn, $args) { |
|
| 131 | 131 | $arguments = func_get_args(); |
| 132 | 132 | return call_user_func_array($fn, array_merge($arguments, $args)); |
| 133 | 133 | }; |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | if ($length === 0) { |
| 145 | 145 | throw new \Exception("pipe requires at least one argument"); |
| 146 | 146 | } |
| 147 | - return function () use ($arguments) { |
|
| 147 | + return function() use ($arguments) { |
|
| 148 | 148 | $internalArguments = func_get_args(); |
| 149 | 149 | $initialValue = call_user_func_array($arguments[0], $internalArguments); |
| 150 | - $accumulator = function ($acc, $it) { |
|
| 150 | + $accumulator = function($acc, $it) { |
|
| 151 | 151 | return call_user_func_array($it, [$acc]); |
| 152 | 152 | }; |
| 153 | 153 | return array_reduce(drop(0, $arguments), $accumulator, $initialValue); |