Function reduceLeft

  • Make a Matcher that takes 0 or more matches from the same parser and reduces them into one value in left-to-right (first-to-last) order.

    Note: accumulator is the left (first) argument.

    Use leftAssoc1 if you have an initial value to be parsed first.

    Implementation is based on chainReduce and map.

    Type Parameters

    • TToken

    • TOptions

    • TAcc

    • TValue

    Parameters

    • acc: TAcc

      Initial value for the accumulator.

    • p: Parser<TToken, TOptions, TValue>

      Parser for each next value.

    • reducer: ((acc: TAcc, v: TValue, data: Data<TToken, TOptions>, i: number, j: number) => TAcc)

      Function to combine the accumulator and each parsed value.

        • (acc: TAcc, v: TValue, data: Data<TToken, TOptions>, i: number, j: number): TAcc
        • Parameters

          • acc: TAcc

            Accumulated value.

          • v: TValue

            Value from each successful parsing.

          • data: Data<TToken, TOptions>

            Data object (tokens and options).

          • i: number

            Position before current match.

          • j: number

            Position after current match.

          Returns TAcc

    Returns Matcher<TToken, TOptions, TAcc>

Generated using TypeDoc