Created
April 15, 2019 10:54
-
-
Save tonyonodi/7a74b50c83f53a1d88beb02336507f60 to your computer and use it in GitHub Desktop.
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
const cond = <A, B>( | |
pairs: [(input: A) => boolean, (input: A) => B][], | |
fallback: (input: A) => B | |
) => (value: A): B => { | |
const pair = pairs.find(([predicate]) => predicate(value)); | |
return pair ? pair[1](value) : fallback(value); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment