set [[defaultEvaluator]] with evaluator param
if evaluator is not an Evaluator, use returnValue
Iterate on stack entries If value match predicate, return R value from Evaluator
Add in [[stack]] an entry of <Predicate
if comparator is not a Predicate, use objectStrictLike if typeof comparator is object else strictEqual
if evaluator is not an Evaluator, use returnValue
Generated using TypeDoc
You can use PatternMatching class as a evoluated Pattern Strategy
Compile strategy you need, and execute the adapted startegy matched by executed value.
import http from 'http'; import https from 'https'; import http2 from 'http2'; import { PatternMatching } from '@tpoisseau/pattern-matching'; import { throwError } from '@tpoisseau/pattern-matching/evaluators'; const serverStrategies = new PatternMatching() .match('http', http) .match('https', https) .match('http2', http2) .default(throwError('Unsupported protocol')) const createStrategies = new PatternMatching() .match(protocol => /^https?$/.test(protocol), 'createServer') .match('http2', 'createSecureServer') .default(throwError('Unsupported protocol')) serverStrategies.exec('http')[createStrategies.exec('http')]() serverStrategies.exec('https')[createStrategies.exec('https')]() serverStrategies.exec('http2')[createStrategies.exec('http2')]()
Predicate
Evaluator