Travis build: 1976

This commit is contained in:
30secondsofcode
2018-04-19 17:07:16 +00:00
parent d913e63644
commit 13769cce1f
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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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
```