Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "@tpoisseau/pattern-matching/evaluators"

Index

Type aliases

Evaluator

Evaluator<PV, R>: function

Type parameters

  • PV

  • R

Type declaration

    • (patternValue: PV): R
    • Parameters

      • patternValue: PV

      Returns R

ExtractSchemaCallback

ExtractSchemaCallback: function

Type declaration

Functions

extractValue

  • extractValue<EV, PV, R>(schema: EV): Evaluator<PV, R>
  • create an extractor function.

    see

    ExtractSchema for understand how extractor will map data

    example
    import { extractValue } from '@tpoisseau/pattern-matching/evaluators';
    
    const mapper = extractValue({
     foo: true,
     bar: false, // for the demo but it's no use
     baz: value => value.toto,
     tata: 'foo',
    });
    
    > mapper({foo: 42, bar: 'baz', baz: 'foo', toto: 'tata'})
    > {
        foo: 42,
        baz: 'tata',
        tata: 42
    }

    Type parameters

    Parameters

    • schema: EV

      define mapping of object

    Returns Evaluator<PV, R>

    a function who generate an object populate with key from schema and value from obj

returnValue

  • returnValue<EV, PV, R>(value: EV): Evaluator<PV, R>
  • Create a function who will return value

    example
    import { returnValue } from '@tpoisseau/pattern-matching/evaluators';
    
    const getFoo = returnValue('foo');
    
    > getFoo()
    > 'foo'
    > getFoo('bar')
    > 'foo'

    Type parameters

    • EV

    • PV

    • R: EV

    Parameters

    • value: EV

    Returns Evaluator<PV, R>

throwError

  • throwError<EV, PV, R>(error: EV): Evaluator<PV, R>

throwNewError

  • throwNewError<EV, PV, R>(ErrorClass: EV): Evaluator<PV, R>
  • When evaluator is called, throw new ErrorClass(PV)

    Type parameters

    • EV: ErrorConstructor

    • PV

    • R

    Parameters

    • ErrorClass: EV

    Returns Evaluator<PV, R>

Generated using TypeDoc