whymarrh / ts-match

A small matching library for TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ts-match

A small matching library for TypeScript. The API is a single function defined as:

function match<T, R>(input: T, defaultCase: IDefaultCase<R>, ...cases: ICase<T, R>[]): R

Example:

const s: Foo = new C(5, `test string`);
const result = match<Foo, number>(s,
    _(-42),
    when(A, s => s.a),
    when(B, s => s.b),
    when(C, s => s.c),
);

Quick start

Install via:

$ yarn add ts-match

About

A small matching library for TypeScript

License:ISC License


Languages

Language:TypeScript 93.5%Language:JavaScript 6.5%