Created
July 13, 2017 12:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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