Update and rename coalesce-factory.md to coalesceFactory.md
This commit is contained in:
@ -1,11 +0,0 @@
|
|||||||
### Coalesce factory
|
|
||||||
|
|
||||||
Returns a customized coalesce function that returns the first argument
|
|
||||||
that returns true from the provided argument validation function.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const coalesceFactory = valid => (...args) => args.find(valid)
|
|
||||||
|
|
||||||
// const customCoalesce = coalesceFactory(_ => ![null, undefined, "", NaN].includes(_))
|
|
||||||
// customCoalesce(undefined, null, NaN, "", "Waldo") //-> "Waldo"
|
|
||||||
```
|
|
||||||
11
snippets/coalesceFactory.md
Normal file
11
snippets/coalesceFactory.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
### coalesceFactory
|
||||||
|
|
||||||
|
Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function.
|
||||||
|
|
||||||
|
Use `Array.find()` to return the first argument that returns `true` from the provided argument validation function.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const coalesceFactory = valid => (...args) => args.find(valid);
|
||||||
|
// const customCoalesce = coalesceFactory(_ => ![null, undefined, "", NaN].includes(_))
|
||||||
|
// customCoalesce(undefined, null, NaN, "", "Waldo") //-> "Waldo"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user