This repository was archived by the owner on Feb 16, 2021. It is now read-only.
v2.2.1
-
Experimental
- pattern matching #121
// this example uses ES6 syntax const A = t.struct({...}); const result = t.match(1, t.String, (s) => 'a string', t.Number, (n) => n > 2, (n) => 'a number gt 2', // case with a guard (optional) t.Number, (n) => 'a number lte 2', A, (a) => 'an instance of A', t.Any, (x) => 'other...' // catch all ); console.log(result); // => 'a number lte 2'