Travis build: 1976

This commit is contained in:
30secondsofcode
2018-04-19 17:07:16 +00:00
parent 73bb5b0509
commit 9a09437593
13 changed files with 42 additions and 16 deletions

View File

@ -267,6 +267,7 @@ average(1, 2, 3);
* [`times`](#times)
* [`uncurry`](#uncurry)
* [`unfold`](#unfold)
* [`when`](#when)
</details>
@ -4694,6 +4695,30 @@ unfold(f, 10); // [-10, -20, -30, -40, -50]
<br>[⬆ Back to top](#table-of-contents)
### when
Tests a value, `x`, against a predicate function. If `true`, return `fn(x)`. Else, return `x`.
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);
```
<details>
<summary>Examples</summary>
```js
const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2);
doubleEvenNumbers(2); // 4
doubleEvenNumbers(1); // 1
```
</details>
<br>[⬆ Back to top](#table-of-contents)
---
## ➗ Math