Provide a pattern-matching like syntax with functional fluent chainable api
Think pattern
as switch
keyword and match
as case
keyword but without need to break
the switch-case
expression
match
param should be a Predicate, if not create a predicate with strictEqualmatch
param should be an Evaluator, if not create an Evaluator with returnValueYou could set a a default evaluator (take pattern value as argument) return what you want
If a ProxyPatternMatching or PatternMatching is executed with no matching value. It will return the pattern value by default.
Use .default(evaluator)
for override
Generated using TypeDoc
Install
npm install @tpoisseau/pattern-matching npm install 'https://github.com/tpoisseau/js-pattern-matching#1.0.3'
Use
import pattern, {PatternMatching} from '@tpoisseau/pattern-matching'; import * as comparators from '@tpoisseau/pattern-matching/comparators'; import * as evaluators from '@tpoisseau/pattern-matching/evaluators';