Travis build: 1976
This commit is contained in:
@ -5,14 +5,11 @@ Tests a value, `x`, against a predicate function. If `true`, return `fn(x)`. Els
|
||||
Return a function expecting a single value, `x`, that returns the appropriate value based on `pred`.
|
||||
|
||||
```js
|
||||
const when = (pred, whenTrue) => (x) => pred(x) ? whenTrue(x) : x;
|
||||
const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x);
|
||||
```
|
||||
|
||||
```js
|
||||
const doubleEvenNumbers = when(
|
||||
(x) => x % 2 === 0,
|
||||
(x) => x * 2
|
||||
);
|
||||
const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2);
|
||||
doubleEvenNumbers(2); // 4
|
||||
doubleEvenNumbers(1); // 1
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user