Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/ts_matches/src/matches.ts>matches

Being able to pattern match in typescript
Latest
variable matches
import { matches } from "https://deno.land/x/ts_matches@v5.4.0/src/matches.ts";

Want to be able to bring in the declarative nature that a functional programming language feature of the pattern matching and the switch statement. With the destructors the only thing left was to find the correct structure then move move forward. Using a structure in chainable fashion allows for a syntax that works with typescript while looking similar to matches statements in other languages

Use: matches('a value').when(matches.isNumber, (aNumber) => aNumber + 4).defaultTo('fallback value')