Class StreamImpl<S, T>

The default implementation of Stream works with two input functions:

  • The first function creates the initial state of an iteration.
  • The second function gets the current state as argument and returns an IteratorResult.

Type Parameters

  • S
  • T

Hierarchy (view full)

Implements

Constructors

Properties

nextFn: ((state: S) => IteratorResult<T, any>)
startFn: (() => S)

Methods

  • Returns a stream containing only the distinct elements from this stream. Equality is determined with the same rules as a standard Set.

    Type Parameters

    • Key = T

    Parameters

    • Optionalby: ((element: T) => Key)

      A function returning the key used to check equality with a previous stream element. If omitted, the stream elements themselves are used for comparison.

        • (element): Key
        • Parameters

          • element: T

          Returns Key

    Returns Stream<T>

  • Determines whether all members of the stream satisfy the specified test.

    Type Parameters

    • U

    Parameters

    • predicate: ((value: T) => value is U)

      This method calls the predicate function for each element in the stream until the predicate returns a value which is coercible to the Boolean value false, or until the end of the stream.

        • (value): value is U
        • Parameters

          • value: T

          Returns value is U

    Returns this is Stream<U> & StreamImpl<S, T>

  • Determines whether all members of the stream satisfy the specified test.

    Parameters

    • predicate: ((value: T) => unknown)

      This method calls the predicate function for each element in the stream until the predicate returns a value which is coercible to the Boolean value false, or until the end of the stream.

        • (value): unknown
        • Parameters

          • value: T

          Returns unknown

    Returns boolean

  • Returns a stream that contains all elements that don't exist in the other iterable. Equality is determined with the same rules as a standard Set.

    Type Parameters

    • Key = T

    Parameters

    • other: Iterable<T>

      The elements that should be exluded from this stream.

    • Optionalkey: ((element: T) => Key)

      A function returning the key used to check quality. If omitted, the stream elements themselves are used for comparison.

        • (element): Key
        • Parameters

          • element: T

          Returns Key

    Returns Stream<T>

  • Returns the elements of the stream that meet the condition specified in a callback function. The function is called when the resulting stream elements are actually accessed, so accessing the resulting stream multiple times means the function is also called multiple times for each element of the stream.

    Type Parameters

    • U

    Parameters

    • predicate: ((value: T) => value is U)

      Lazily evaluated function checking a condition on stream elements.

        • (value): value is U
        • Parameters

          • value: T

          Returns value is U

    Returns Stream<U> & StreamImpl<S, T>

  • Returns the elements of the stream that meet the condition specified in a callback function. The function is called when the resulting stream elements are actually accessed, so accessing the resulting stream multiple times means the function is also called multiple times for each element of the stream.

    Parameters

    • predicate: ((value: T) => unknown)

      Lazily evaluated function checking a condition on stream elements.

        • (value): unknown
        • Parameters

          • value: T

          Returns unknown

    Returns Stream<T> & StreamImpl<S, T>

  • Returns the value of the first element in the stream that meets the condition, or undefined if there is no such element.

    Type Parameters

    • S

    Parameters

    • predicate: ((value: T) => value is S)

      This method calls predicate once for each element of the stream, in ascending order, until it finds one where predicate returns a value which is coercible to the Boolean value true.

        • (value): value is S
        • Parameters

          • value: T

          Returns value is S

    Returns undefined | S

  • Returns the value of the first element in the stream that meets the condition, or undefined if there is no such element.

    Parameters

    • predicate: ((value: T) => unknown)

      This method calls predicate once for each element of the stream, in ascending order, until it finds one where predicate returns a value which is coercible to the Boolean value true.

        • (value): unknown
        • Parameters

          • value: T

          Returns unknown

    Returns undefined | T

  • Returns the index of the first element in the stream that meets the condition, or -1 if there is no such element.

    Parameters

    • predicate: ((value: T) => unknown)

      This method calls predicate once for each element of the stream, in ascending order, until it finds one where predicate returns a value which is coercible to the Boolean value true.

        • (value): unknown
        • Parameters

          • value: T

          Returns unknown

    Returns number

  • Calls a defined callback function on each element of the stream and then flattens the result into a new stream. This is identical to a map followed by flat with depth 1.

    Type Parameters

    • U

    Parameters

    • callbackfn: ((value: T) => U | Iterable<U>)

      Lazily evaluated function mapping stream elements.

        • (value): U | Iterable<U>
        • Parameters

          • value: T

          Returns U | Iterable<U>

    Returns Stream<U>

  • Performs the specified action for each element in the stream.

    Parameters

    • callbackfn: ((value: T, index: number) => void)

      Function called once for each element in the stream.

        • (value, index): void
        • Parameters

          • value: T
          • index: number

          Returns void

    Returns void

  • Determines whether the stream includes a certain element, returning true or false as appropriate.

    Parameters

    • searchElement: T

      The element to search for.

    Returns boolean

  • Returns the index of the first occurrence of a value in the stream, or -1 if it is not present.

    Parameters

    • searchElement: T

      The value to locate in the array.

    • fromIndex: number = 0

      The stream index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

    Returns number

  • Adds all elements of the stream into a string, separated by the specified separator string.

    Parameters

    • separator: string = ','

      A string used to separate one element of the stream from the next in the resulting string. If omitted, the steam elements are separated with a comma.

    Returns string

  • Returns a stream that yields the results of calling the specified callback function on each element of the stream. The function is called when the resulting stream elements are actually accessed, so accessing the resulting stream multiple times means the function is also called multiple times for each element of the stream.

    Type Parameters

    • U

    Parameters

    • callbackfn: ((value: T) => U)

      Lazily evaluated function mapping stream elements.

        • (value): U
        • Parameters

          • value: T

          Returns U

    Returns Stream<U>

  • Type Parameters

    • U

    Parameters

    • iterator: Iterator<T, any, undefined>
    • callbackfn: ((previousValue: T | U, currentValue: T) => U)
        • (previousValue, currentValue): U
        • Parameters

          • previousValue: T | U
          • currentValue: T

          Returns U

    • OptionalinitialValue: U

    Returns undefined | T | U

  • Calls the specified callback function for all elements in the stream. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Parameters

    • callbackfn: ((previousValue: T, currentValue: T) => T)

      This method calls the function once for each element in the stream, providing the previous and current values of the reduction.

        • (previousValue, currentValue): T
        • Parameters

          • previousValue: T
          • currentValue: T

          Returns T

    Returns undefined | T

  • Calls the specified callback function for all elements in the stream. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Type Parameters

    • U = T

    Parameters

    • callbackfn: ((previousValue: U, currentValue: T) => U)

      This method calls the function once for each element in the stream, providing the previous and current values of the reduction.

        • (previousValue, currentValue): U
        • Parameters

          • previousValue: U
          • currentValue: T

          Returns U

    • initialValue: U

      If specified, initialValue is used as the initial value to start the accumulation. The first call to the function provides this value as an argument instead of a stream value.

    Returns U

  • Calls the specified callback function for all elements in the stream, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Parameters

    • callbackfn: ((previousValue: T, currentValue: T) => T)

      This method calls the function once for each element in the stream, providing the previous and current values of the reduction.

        • (previousValue, currentValue): T
        • Parameters

          • previousValue: T
          • currentValue: T

          Returns T

    Returns undefined | T

  • Calls the specified callback function for all elements in the stream, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Type Parameters

    • U = T

    Parameters

    • callbackfn: ((previousValue: U, currentValue: T) => U)

      This method calls the function once for each element in the stream, providing the previous and current values of the reduction.

        • (previousValue, currentValue): U
        • Parameters

          • previousValue: U
          • currentValue: T

          Returns U

    • initialValue: U

      If specified, initialValue is used as the initial value to start the accumulation. The first call to the function provides this value as an argument instead of an array value.

    Returns U

  • Determines whether any member of the stream satisfies the specified test.

    Parameters

    • predicate: ((value: T) => unknown)

      This method calls the predicate function for each element in the stream until the predicate returns a value which is coercible to the Boolean value true, or until the end of the stream.

        • (value): unknown
        • Parameters

          • value: T

          Returns unknown

    Returns boolean

  • Returns a stream that skips the first skipCount elements from this stream.

    Parameters

    • skipCount: number = 1

      The number of elements to skip. If this is larger than the number of elements in the stream, an empty stream is returned. Defaults to 1.

    Returns Stream<T>

  • Collects all elements of this stream into a Map, applying the provided functions to determine keys and values.

    Type Parameters

    • K = T
    • V = T

    Parameters

    • OptionalkeyFn: ((e: T) => K)

      The function to derive map keys. If omitted, the stream elements are used as keys.

        • (e): K
        • Parameters

          Returns K

    • OptionalvalueFn: ((e: T) => V)

      The function to derive map values. If omitted, the stream elements are used as values.

        • (e): V
        • Parameters

          Returns V

    Returns Map<K, V>