Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StateOp<Elem, St, Res>

Generic Collector type Represents a generic collectable computation

typeparam

the input element type

typeparam

the intermediate state type

typeparam

the output value type

Type parameters

  • Elem

  • St

  • Res

Hierarchy

  • StateOp

Index

Accessors

createInitState

  • get createInitState(): function

escape

  • get escape(): undefined | function

nextState

  • get nextState(): function

stateToResult

  • get stateToResult(): function

Methods

appendInput

  • appendInput(...elems: NonEmpty<Elem>): Op<Elem, Res>
  • Returns a Collector where the given elems are appended to the input received. Note: since the appending happens when the state is retrieved, getting the result multiple times can give unpredictable results.

    Parameters

    • Rest ...elems: NonEmpty<Elem>

      the elements to prepent

    Returns Op<Elem, Res>

distinctByInput

  • distinctByInput<K>(keyFun: function): Op<Elem, Res>
  • Returns a Collector that processes every input element for which the given keyFun returns the same key value at most once.

    Type parameters

    • K

      the element key type

    Parameters

    • keyFun: function

      a function taking an input element and its index, and returning a key

        • (value: Elem, index: number): K
        • Parameters

          • value: Elem
          • index: number

          Returns K

    Returns Op<Elem, Res>

distinctInput

  • distinctInput(): Op<Elem, Res>

dropInput

  • dropInput(amount: number): Op<Elem, Res>
  • Returns a Collector that skips the initial amount values of the input.

    Parameters

    • amount: number

      the amount of input values to skip

    Returns Op<Elem, Res>

dropLastInput

  • dropLastInput(amount: number): Op<Elem, Res>
  • Returns a Collector that skips the last amount values of the input.

    Parameters

    • amount: number

      the amount of last input values to skip

    Returns Op<Elem, Res>

dropWhileInput

  • dropWhileInput(pred: Pred<Elem>): Op<Elem, Res>
  • Returns a Collector that skips elements of the input as long as given pred is true. Then processes all other elements.

    Parameters

    • pred: Pred<Elem>

      a predicate over the input elements

    Returns Op<Elem, Res>

filterChangedInput

  • filterChangedInput(): Op<Elem, Res>

filterInput

  • filterInput(pred: Pred<Elem>): Op<Elem, Res>
  • Returns a Collector where the input is filtered according to the given pred predicate.

    Parameters

    • pred: Pred<Elem>

      a predicate over input elements

    Returns Op<Elem, Res>

intersperseInput

  • intersperseInput(elem: Elem): Op<Elem, Res>
  • Returns a Collector where between each two elements, the given elem is added as extra input.

    Parameters

    • elem: Elem

      the element to insert between input elements

    Returns Op<Elem, Res>

mapInput

  • mapInput<A2>(mapFun: MapFun<A2, Elem>): Op<A2, Res>
  • Returns a Collector where the input is mapped from a source type A2 to the expected input elements of type A.

    Type parameters

    • A2

      the new source/input type

    Parameters

    • mapFun: MapFun<A2, Elem>

      a function mapping from the new input type A2 to the expected input type A

    Returns Op<A2, Res>

mapResult

  • mapResult<R2>(mapFun: function): Op<Elem, R2>
  • Returns a Collector where the output value(s) are mapped using the given mapFun

    Type parameters

    • R2

      the new output type

    Parameters

    • mapFun: function

      a function from current output type R to new output type R2

        • (result: Res): R2
        • Parameters

          • result: Res

          Returns R2

    Returns Op<Elem, R2>

monitorInput

  • monitorInput(tag?: string, effect?: MonitorEffect<[Elem, St]>): Op<Elem, Res>
  • Performs given monitorEffect for each input element. By default does a console.log with the given tag.

    Parameters

    • Default value tag: string = ""

      a tag to use with logging

    • Default value effect: MonitorEffect<[Elem, St]> = defaultMonitorEffect

      the effect to perform for each input element

    Returns Op<Elem, Res>

patchElemInput

  • patchElemInput(elem: Elem, remove: number, insert?: Iterable<Elem>, amount?: undefined | number): Op<Elem, Res>
  • Returns a Collector where, at the occurence of given elem element, remove elements are skipped, and insert elements are inserted, at most amount times.

    Parameters

    • elem: Elem

      the element to find

    • remove: number

      the amount of elements to skip when the element is found

    • Optional insert: Iterable<Elem>

      the optional iterable to insert when the element is found

    • Optional amount: undefined | number

      the maximum amount of time to replace an element

    Returns Op<Elem, Res>

patchWhereInput

  • patchWhereInput(pred: Pred<Elem>, remove: number, insert?: undefined | function, amount?: undefined | number): Op<Elem, Res>
  • Returns a Collector that skips remove elements at those input elements for which pred returns true, and then inserts th e optional iterable resulting from calling insert with the found element and its index, at most amount times.

    Parameters

    • pred: Pred<Elem>

      the predicate over input elements

    • remove: number

      the amount of elements to skip when pred is true

    • Optional insert: undefined | function

      the iterable elements to insert when pred is true

    • Optional amount: undefined | number

      the maximum amount of times to replace an input element

    Returns Op<Elem, Res>

prependInput

  • prependInput(...elems: NonEmpty<Elem>): Op<Elem, Res>

sampleInput

  • sampleInput(nth: number): Op<Elem, Res>
  • Returns a Collector that processes each nth element of the input elements.

    Parameters

    • nth: number

      specifies the index of which each element that has a multiple of nth will be processed

    Returns Op<Elem, Res>

sliceInput

  • sliceInput(from: number, amount: number): Op<Elem, Res>
  • Returns a Collector that only process amount elements from the given from index of the input elements.

    Parameters

    • from: number

      the index to start processing elements

    • amount: number

      the amount of elements to process

    Returns Op<Elem, Res>

takeInput

  • takeInput(amount: number): Op<Elem, Res>
  • Returns a Collector that only processes the initial amount values of the input.

    Parameters

    • amount: number

      the amount of input values to process

    Returns Op<Elem, Res>

takeLastInput

  • takeLastInput(amount: number): Op<Elem, Res>
  • Returns a Collector that only processes the last amount values of the input.

    Parameters

    • amount: number

      the amount of last input values to process

    Returns Op<Elem, Res>

takeWhileInput

  • takeWhileInput(pred: Pred<Elem>): Op<Elem, Res>
  • Returns a Collector that only processes elements from the input as long as the given pred is true. Ignores the rest.

    Parameters

    • pred: Pred<Elem>

      a predicate over the input elements

    Returns Op<Elem, Res>

Static create

  • create<Elem, St, Res>(definition: object): StateOp<Elem, St, Res>
  • Creates a new Collector object from element type A to result type R

    typeparam

    the input element type

    typeparam

    the intermediate state type

    typeparam

    the result type

    Type parameters

    • Elem

    • St

    • Res

    Parameters

    • definition: object

      the definition of the state collector, containing:

      • initState: the initial state of the Collector, optionally lazy
      • nextState: a function taking the current state S and the next element A and returns the next state S
      • stateToResult: a function that takes a state S and maps it to a result R
      • escape?: a predicate over a state S indicating whether its value can still ever change

    Returns StateOp<Elem, St, Res>

Generated using TypeDoc