Files
30-seconds-of-code/snippets/coalesce-factory.md
2017-12-17 14:09:04 -08:00

388 B

Coalesce factory

Returns a customized coalesce function that returns the first argument that returns true from the provided argument validation function.

const coalesceFactory = valid => (...args) => args.find(valid)

// const customCoalesce = coalesceFactory(_ => ![null, undefined, "", NaN].includes(_))
// customCoalesce(undefined, null, NaN, "", "Waldo") //-> "Waldo"