Function matchOn

  • Type Parameters

    • MATCH extends string | number

    Parameters

    Returns (<VALUE>(on, cases) => Maybe<VALUE>)

    See

    test for matchOn

    Example:

    enum Thing {
    One = 'One',
    Two = 'Two',
    Three = 'Three'
    }

    const matchThings = matchOn(Object.values(Thing));

    matchThings(Thing.Two, {
    [Thing.One]: () => 'I am one',
    [Thing.Two]: () => 'I am two',
    [Thing.Three]: () => 'I am three',
    }).orElse('none of the above'); // produces: "I am two"

    matchThings(undefined, {
    [Thing.One]: () => 'I am one',
    [Thing.Two]: () => 'I am two',
    [Thing.Three]: () => 'I am three',
    }).orElse('none of the above'); // produces: "none of the above"