Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "public/strike"

Index

Functions

Functions

Const strike

  • strike<TIn, TOut>(val: TIn, ...matchers: Array<AnyExecutor<TIn, TOut>>): TIn | TOut
  • description

    Use this function when you have a value and you want to test it against a pattern.

    strike will iterate through your Matchers and use the first match's Transformer to map val to a TOut.

    strike is comparable to the match operator in Rust, F#, and other languages with idiomatic Pattern Matching.

    see

    {@link pattern}

    since

    1.0.0

    example
    enum Coin {
        Quarter,
        Nickel,
    }
    
    function getValue(coin: Coin): number {
        return strike(coin,
            match(Coin.Quarter, 0.25),
            match(Coin.Nickel, 0.05),
            otherwise(0)
        );
    }
    
    assertEq(getValue(Coin.Quarter), 0.25);
    assertEq(getValue(Coin.Nickel), 0.05);

    Type parameters

    • TIn

    • TOut

    Parameters

    • val: TIn
    • Rest ...matchers: Array<AnyExecutor<TIn, TOut>>

    Returns TIn | TOut

Generated using TypeDoc