1 | <?php |
||
17 | class lambda |
||
18 | { |
||
19 | /** |
||
20 | * Creates a new Prototype object |
||
21 | * @param $properties |
||
22 | * @return lambda\Prototype |
||
23 | */ |
||
24 | 5 | public static function prototype($properties) |
|
30 | |||
31 | /** |
||
32 | * Returns a function with the given arguments already entered or partially applied. |
||
33 | * @param callable $callable The function to curry |
||
34 | * @param array $partialArgs unlimited Optional arguments to curry the function with |
||
35 | * @param array $defaultArgs optional default values |
||
36 | * @return callable |
||
37 | */ |
||
38 | 2 | public static function partial(callable $callable, $partialArgs, $defaultArgs = []) |
|
44 | |||
45 | 2 | private static function partialMerge($partialArgs, $addedArgs, $defaultArgs = []) |
|
63 | |||
64 | /** |
||
65 | * Returns a function with named arguments. The peppered function accepts one argument - a named array of values |
||
66 | * @param callable $callable The function or method to pepper |
||
67 | * @param array $namedArgs Optional. The named arguments to pepper the function with, the order must be the order |
||
68 | * in which the unpeppered function expects them. If not set, pepper will use Reflection to get them. |
||
69 | * Format is [ 'argumentName' => 'defaultValue' ] |
||
70 | * @return callable |
||
71 | */ |
||
72 | 1 | public static function pepper(callable $callable, $namedArgs=null) |
|
87 | |||
88 | /** |
||
89 | * Returns a method that will generate and call the given function only once and return its result for every call. |
||
90 | * The first call generates the result. Each subsequent call simply returns that same result. This allows you |
||
91 | * to create in-context singletons for any kind of object. |
||
92 | * <code> |
||
93 | * $proto = \arc\lambda::prototype([ |
||
94 | * 'getSingleton' => \arc\lambda::singleton( function () { |
||
95 | * return new ComplexObject(); |
||
96 | * }) |
||
97 | * ]); |
||
98 | * </code> |
||
99 | * @param callable $f The function to generate the singleton. |
||
100 | * @return mixed The singleton. |
||
101 | */ |
||
102 | public static function singleton($f) |
||
113 | } |
||
114 |