|
1
|
|
|
<?php |
|
2
|
|
|
namespace Aerophant\Ramda; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Number → Number → Number |
|
6
|
|
|
* @param integer|float|double $firstValue |
|
7
|
|
|
* @param integer|float|double $secondValue |
|
8
|
|
|
* @return integer|float|double|\Closure |
|
9
|
|
|
*/ |
|
10
|
|
|
function add() |
|
11
|
|
|
{ |
|
12
|
|
|
$add = function ($firstValue, $secondValue) { |
|
13
|
|
|
return $firstValue + $secondValue; |
|
14
|
|
|
}; |
|
15
|
|
|
$arguments = func_get_args(); |
|
16
|
|
|
$curried = curryN($add, 2); |
|
17
|
|
|
return call_user_func_array($curried, $arguments); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Number → Number → Number |
|
22
|
|
|
* @param integer|float|double $firstValue |
|
23
|
|
|
* @param integer|float|double $secondValue |
|
24
|
|
|
* @return integer|float|double|\Closure |
|
25
|
|
|
*/ |
|
26
|
|
|
function divide() |
|
27
|
|
|
{ |
|
28
|
|
|
$divide = function ($firstValue, $secondValue) { |
|
29
|
|
|
return $firstValue / $secondValue; |
|
30
|
|
|
}; |
|
31
|
|
|
$arguments = func_get_args(); |
|
32
|
|
|
$curried = curryN($divide, 2); |
|
33
|
|
|
return call_user_func_array($curried, $arguments); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param double|float|integer $value |
|
38
|
|
|
* @return double|float|integer |
|
39
|
|
|
*/ |
|
40
|
|
|
function inc() |
|
41
|
|
|
{ |
|
42
|
|
|
$inc = function ($value) { |
|
43
|
|
|
return $value + 1; |
|
44
|
|
|
}; |
|
45
|
|
|
$arguments = func_get_args(); |
|
46
|
|
|
$curried = curryN($inc, 1); |
|
47
|
|
|
return call_user_func_array($curried, $arguments); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Number → Number → Number |
|
52
|
|
|
* @param integer|float|double $firstValue |
|
53
|
|
|
* @param integer|float|double $secondValue |
|
54
|
|
|
* @return integer|float|double|\Closure |
|
55
|
|
|
*/ |
|
56
|
|
|
function multiply() |
|
57
|
|
|
{ |
|
58
|
|
|
$multiply = function ($firstValue, $secondValue) { |
|
59
|
|
|
return $firstValue * $secondValue; |
|
60
|
|
|
}; |
|
61
|
|
|
$arguments = func_get_args(); |
|
62
|
|
|
$curried = curryN($multiply, 2); |
|
63
|
|
|
return call_user_func_array($curried, $arguments); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Number → Number → Number |
|
68
|
|
|
* @param integer|float|double $firstValue |
|
69
|
|
|
* @param integer|float|double $secondValue |
|
70
|
|
|
* @return integer|float|double|\Closure |
|
71
|
|
|
*/ |
|
72
|
|
|
function subtract() |
|
73
|
|
|
{ |
|
74
|
|
|
$subtract = function ($firstValue, $secondValue) { |
|
75
|
|
|
return $firstValue - $secondValue; |
|
76
|
|
|
}; |
|
77
|
|
|
$arguments = func_get_args(); |
|
78
|
|
|
$curried = curryN($subtract, 2); |
|
79
|
|
|
return call_user_func_array($curried, $arguments); |
|
80
|
|
|
} |
|
81
|
|
|
|