Travis build: 1976
This commit is contained in:
25
README.md
25
README.md
@ -267,6 +267,7 @@ average(1, 2, 3);
|
|||||||
* [`times`](#times)
|
* [`times`](#times)
|
||||||
* [`uncurry`](#uncurry)
|
* [`uncurry`](#uncurry)
|
||||||
* [`unfold`](#unfold)
|
* [`unfold`](#unfold)
|
||||||
|
* [`when`](#when)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -4694,6 +4695,30 @@ unfold(f, 10); // [-10, -20, -30, -40, -50]
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<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
|
## ➗ 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
@ -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`.
|
Return a function expecting a single value, `x`, that returns the appropriate value based on `pred`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const when = (pred, whenTrue) => (x) => pred(x) ? whenTrue(x) : x;
|
const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const doubleEvenNumbers = when(
|
const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2);
|
||||||
(x) => x % 2 === 0,
|
|
||||||
(x) => x * 2
|
|
||||||
);
|
|
||||||
doubleEvenNumbers(2); // 4
|
doubleEvenNumbers(2); // 4
|
||||||
doubleEvenNumbers(1); // 1
|
doubleEvenNumbers(1); // 1
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user