Last active
July 18, 2018 10:04
-
-
Save stevewadsworth/e04bdcaf323656d4f9812b66084d1359 to your computer and use it in GitHub Desktop.
withEither
This file contains hidden or 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
| /** | |
| * withEither takes three parameters and returns a function. | |
| * When the returned function is called a decision is made to call either the first or second functions. | |
| * | |
| * @param {function} funcTrue The function to call if choice returns true | |
| * @param {function} funcFalse The function to call if choice returns false | |
| * @param {function} choice The function which returns true or false depending on the input params | |
| * @returns {function} | |
| */ | |
| const withEither = (funcTrue, funcFalse, choice) => { | |
| return (...params) => { | |
| if (choice(...params)) { | |
| return funcTrue(...params); | |
| } | |
| return funcFalse(...params); | |
| }; | |
| }; | |
| export default withEither; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment