Skip to content

Instantly share code, notes, and snippets.

@astraloverflow
Created May 26, 2019 00:47
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 astraloverflow/8027794fce7a775856d9e43fbdf4e7f1 to your computer and use it in GitHub Desktop.
Save astraloverflow/8027794fce7a775856d9e43fbdf4e7f1 to your computer and use it in GitHub Desktop.
/*! https://codeburst.io/alternative-to-javascripts-switch-statement-with-a-functional-twist-3f572787ba1c */
const match = x => {
const matched = y => ({
on: () => matched(y),
otherwise: () => y
})
return ({
on: (pred, fn) => (pred(x) ? matched(fn(x)) : match(x)),
otherwise: fn => fn(x)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment