My Docs
BlogGithubLinkedin
Snippets
Snippets
  • Snippets
  • Introduction
  • Python
    • Python
      • take
      • symmetric_difference_by
      • sum_of_powers
      • union
      • transpose
      • unfold
      • tail
      • values_only
      • to_binary
      • take_right
      • find_index
      • months_diff
      • celsius_to_fahrenheit
      • bifurcate
      • days_ago
      • chunk_into_n
      • bifurcate_by
      • add_days
      • intersection_by
      • spread
      • head
      • sum_by
      • initialize_2d_list
      • map_dictionary
      • digitize
      • merge_dictionaries
      • includes_any
  • JavaScript
    • Javascript
      • addEventListenerAll
      • coalesceFactory
      • arrayToHTMLList
      • arithmeticProgression
      • castArray
      • both
      • arrayToCSV
      • atob
      • combine
      • capitalize
      • addMultipleListeners
      • any
      • bifurcate
      • coalesceFactory
Powered by GitBook
On this page

Was this helpful?

  1. JavaScript
  2. Javascript

coalesceFactory

Customizes a coalesce function that returns the first argument which is true based on the given validator.

  • Use Array.prototype.find() to return the first argument that returns true from the provided argument validation function, valid.

const coalesceFactory = valid => (...args) => args.find(valid);
const customCoalesce = coalesceFactory(
  v => ![null, undefined, '', NaN].includes(v)
);
customCoalesce(undefined, null, NaN, '', 'Waldo'); // 'Waldo'
PreviousaddEventListenerAllNextarrayToHTMLList

Last updated 3 years ago

Was this helpful?