Skip to content

Instantly share code, notes, and snippets.

@tonyonodi
Created April 15, 2019 10:54
Show Gist options
  • Save tonyonodi/7a74b50c83f53a1d88beb02336507f60 to your computer and use it in GitHub Desktop.
Save tonyonodi/7a74b50c83f53a1d88beb02336507f60 to your computer and use it in GitHub Desktop.
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