@@ 12-21 (lines=10) @@ | ||
9 | /** |
|
10 | * @see http://elixir-lang.org/getting-started/case-cond-and-if.html#if-and-unless |
|
11 | */ |
|
12 | function unless(callable $pred): \Closure |
|
13 | { |
|
14 | return function (callable $callback) use ($pred): \Closure { |
|
15 | return function ($x) use ($pred, $callback) { |
|
16 | return $pred($x) |
|
17 | ? $x |
|
18 | : $callback($x); |
|
19 | }; |
|
20 | }; |
|
21 | } |
|
22 |
@@ 9-18 (lines=10) @@ | ||
6 | ||
7 | const when = __NAMESPACE__.'\when'; |
|
8 | ||
9 | function when(callable $pred): \Closure |
|
10 | { |
|
11 | return function (callable $callback) use ($pred): \Closure { |
|
12 | return function ($x) use ($pred, $callback) { |
|
13 | return $pred($x) |
|
14 | ? $callback($x) |
|
15 | : $x; |
|
16 | }; |
|
17 | }; |
|
18 | } |
|
19 |