Skip to content

Instantly share code, notes, and snippets.

@schmidsi
Created July 13, 2017 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmidsi/04a18ff4640bd19464a845711956bdd7 to your computer and use it in GitHub Desktop.
Save schmidsi/04a18ff4640bd19464a845711956bdd7 to your computer and use it in GitHub Desktop.
functional helper to execute every function in a list and return the value of the first function which not returns false
// functional helper to execute every function in a list
// and return the value of the first function which not returns false
const firstResult = (...args) => functionList =>
functionList.find(f => f(...args))(...args);
// Example (a stupid one):
const decisionList = [
(a, b) => a > b ? 'a greater than b' : false,
(a, b) => a < b ? 'a smaller than b' : false,
() => 'a equal b',
];
const is1BiggerThan2 = firstResult(1, 2)(decisionList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment