Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "fsm"

Index

Functions

fsm

  • fsm<T, C, R>(states: IObjectOf<Matcher<T, C, R>>, ctx: C, initial: string | number, update?: Fn2<C, T, void>): Transducer<T, R>
  • fsm<T, C, R>(states: IObjectOf<Matcher<T, C, R>>, ctx: C, initial: string | number, update?: Fn2<C, T, void>, src?: Iterable<T>): IterableIterator<R>
  • Finite-state machine transducer / iterator with support for single lookahead value.

    remarks

    Takes an object of states and their matchers, an arbitrary context object and an initial state ID (default: "start").

    The returned transducer consumes inputs of type T and produces results of type R. The results are produced by callbacks of the given state matchers. Each can produce any number of values. If a callback returns a result wrapped w/ {@link @thi.ng/transducers#(reduce:1)d}, the FSM causes early termination of the overall transducer pipeline. Failed state callbacks too can produce outputs, but will afterwards terminate the FSM.

    An {@link @thi.ng/errors#IllegalStateError} will be thrown if a transition to an undefined state ID occurs.

    The optional update function will be invoked for each input prior to executing the currently active state matcher. It is intended to update the context object (e.g. to update input location info for generating error messages).

    If the optional src iterable is given, the function returns a transforming iterator of the FSM results.

    Type parameters

    • T

    • C

    • R

    Parameters

    • states: IObjectOf<Matcher<T, C, R>>

      FSM state matchers

    • ctx: C

      FSM context object

    • initial: string | number
    • Optional update: Fn2<C, T, void>

      context update fn

    Returns Transducer<T, R>

  • Type parameters

    • T

    • C

    • R

    Parameters

    • states: IObjectOf<Matcher<T, C, R>>
    • ctx: C
    • initial: string | number
    • Optional update: Fn2<C, T, void>
    • Optional src: Iterable<T>

    Returns IterableIterator<R>

Const reduceResult

  • reduceResult<R>(rfn: ReductionFn<any, R>, acc: any, res: R[]): any
  • Type parameters

    • R

    Parameters

    • rfn: ReductionFn<any, R>
    • acc: any
    • res: R[]

    Returns any

Generated using TypeDoc