Interface TreeStream<T>

A tree stream is used to stream the elements of a tree, for example an AST or CST.

interface TreeStream<T> {
    [iterator](): Iterator<T, any, undefined>;
    concat<T2>(other: Iterable<T2>): Stream<T | T2>;
    count(): number;
    distinct<Key>(by?: ((element: T) => Key)): Stream<T>;
    every<S>(predicate: ((value: T) => value is S)): this is Stream<S>;
    every(predicate: ((value: T) => unknown)): boolean;
    exclude<Key>(other: Iterable<T>, key?: ((element: T) => Key)): Stream<T>;
    filter<S>(predicate: ((value: T) => value is S)): Stream<S>;
    filter(predicate: ((value: T) => unknown)): Stream<T>;
    find<S>(predicate: ((value: T) => value is S)): undefined | S;
    find(predicate: ((value: T) => unknown)): undefined | T;
    findIndex(predicate: ((value: T) => unknown)): number;
    flat<D>(depth?: D): FlatStream<T, D>;
    flatMap<U>(callbackfn: ((value: T) => U | Iterable<U>)): Stream<U>;
    forEach(callbackfn: ((value: T, index: number) => void)): void;
    head(): undefined | T;
    includes(searchElement: T): boolean;
    indexOf(searchElement: T, fromIndex?: number): number;
    isEmpty(): boolean;
    iterator(): TreeIterator<T>;
    join(separator?: string): string;
    limit(maxSize: number): Stream<T>;
    map<U>(callbackfn: ((value: T) => U)): Stream<U>;
    nonNullable(): Stream<NonNullable<T>>;
    reduce(callbackfn: ((previousValue: T, currentValue: T) => T)): undefined | T;
    reduce<U>(callbackfn: ((previousValue: U, currentValue: T) => U), initialValue: U): U;
    reduceRight(callbackfn: ((previousValue: T, currentValue: T) => T)): undefined | T;
    reduceRight<U>(callbackfn: ((previousValue: U, currentValue: T) => U), initialValue: U): U;
    some(predicate: ((value: T) => unknown)): boolean;
    tail(skipCount?: number): Stream<T>;
    toArray(): T[];
    toMap<K, V>(keyFn?: ((e: T) => K), valueFn?: ((e: T) => V)): Map<K, V>;
    toSet(): Set<T>;
    toString(): string;
}

Type Parameters

  • T

Hierarchy (view full)

Implemented by

Methods

  • Returns Iterator<T, any, undefined>

  • 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

    • S

    Parameters

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

      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 S
        • Parameters

          • value: T

          Returns value is S

    Returns this is Stream<S>

  • Parameters

    • predicate: ((value: T) => unknown)
        • (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

    • S

    Parameters

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

      Lazily evaluated function checking a condition on stream elements.

        • (value): value is S
        • Parameters

          • value: T

          Returns value is S

    Returns Stream<S>

  • Parameters

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

          • value: T

          Returns unknown

    Returns Stream<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

  • Parameters

    • predicate: ((value: T) => unknown)
        • (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.

    • OptionalfromIndex: number

      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

    • Optionalseparator: 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>

  • 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

  • Type Parameters

    • U = T

    Parameters

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

          • previousValue: U
          • currentValue: T

          Returns U

    • initialValue: U

    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

  • Type Parameters

    • U = T

    Parameters

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

          • previousValue: U
          • currentValue: T

          Returns U

    • initialValue: U

    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

    • OptionalskipCount: number

      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>