A Stream is a sequence of values that can be manipulated using a variety of methods. Streams are created from iterables, arrays, or using the range, repeat and other factory methods. Streams are lazy, meaning that they do not evaluate their elements until they are consumed by a method that requires it, so-called terminal operations. This allows for efficient processing of large or infinite sequences

Type Parameters

  • T

    The type of the elements in the Stream

Hierarchy

  • Sequencer<T>
    • Stream

Constructors

Properties

Collectors

Collectors are methods that consume the Stream and produce a new value.

Factories

Factories are methods that create new Streams from existing values or iterables.

Terminators

Transformers

Transformers are methods that create a new Stream from the original Stream by transforming the elements in some way.

Constructors

  • Internal

    Type Parameters

    • T

    Parameters

    • sequencer: Sequencer<T>

    Returns Stream<T>

Properties

sequencer: Sequencer<T>

The underlying Sequencer object that provides the elements of the Stream

Collectors

  • Converts the Stream to an array. This will consume the Stream. If the Stream is infinite, this will produce an infinite loop.

    Returns T[]

    An array of the elements in the Stream

    Throws

    Example: Convert a Stream to an array

    const s = Stream.range(5);
    console.log(s.toArray()); // [0, 1, 2, 3, 4]
  • Converts the stream to a Map. This will consume the Stream.

    If the Stream is infinite, this will produce an infinite loop.

    The Stream element type must be a tuple of key-value pairs. Since there is no explicit tuple type in JavaScript/TypeScript, Typescript tuples are expected, that is, an array of length 2, where the first element is the key and the second element is the value.

    Type Parameters

    • K

      The type of the keys in the Map

    • V

      The type of the values in the Map

    Parameters

    Returns Map<K, V>

    A Map constructed from the elements in the Stream

    Throws

    • ArgTypeError If the Stream element type is not a tuple

      This is only enforced in compile time if the Stream is typed properly. The runtime check is not done prior to consumption. so the error will be thrown during consumption. Use with caution with Stream.chain, as it enables chaining streams of different types.

    • ArgCountError if the number of arguments is not 0

    Example: Convert a Stream of key-value pairs to a Map

    const s = Stream.from([
    ["a", 1],
    ["b", 2],
    ["c", 3],
    ] as [string, number][]);
    console.log(s.toMap()); // Map(3) { 'a' => 1, 'b' => 2, 'c' => 3 }
  • Converts the Stream to a Set. This will consume the Stream.

    If the Stream is infinite, this will produce an infinite loop.

    Returns Set<T>

    A Set constructed from the elements in the Stream

    Throws

    Example: Convert a Stream to a Set

    const s = Stream.range(5);
    console.log(s.toSet()); // Set(5) { 0, 1, 2, 3, 4 }

Factories

  • Type Parameters

    • T

      The type of the elements in the Stream

    Returns Stream<T>

    An empty Stream

    Throws

    Example

    console.log(Stream.empty().toArray()); // []
    
  • Create a Stream from an iterable.

    Type Parameters

    • T

      The type of the elements in the iterable and the resulting Stream.

    Parameters

    • iterable: Iterable<T>

    Returns Stream<T>

    A Stream of the elements in the iterable

    Throws

    Example: Create a Stream from an array

    const s = Stream.from([1, 2, 3, 4, 5]);
    console.log(s.toArray()) // [1, 2, 3, 4, 5]

    Example: Create a Stream from a string

     const s = Stream.from("hello");
    console.log(s.toArray()); // ["h", "e", "l", "l", "o"]

    Example: Create a Stream from a Set

     const s = Stream.from(new Set([1, 2, 3, 4, 5]));
    console.log(s.toArray()); // [1, 2, 3, 4, 5]

    Example: Create a Stream from a Map

    const s = Stream.from(new Map([["a", 1], ["b", 2], ["c", 3]]));
    console.log(s.toArray()); // [["a", 1], ["b", 2], ["c", 3]]

    Example: Create a Stream from an iterable

    const s = Stream.from({
    *[Symbol.iterator]() {
    yield 1; yield 2; yield 3;
    }
    });
    console.log(s.toArray()); // [1, 2, 3]

    Example: Create a Stream from a generator function

    function* gen() {
    for (let i = 0; i < 5; i++) {
    yield i;
    }
    }

    const s = Stream.from(gen());
    console.log(s.toArray()); // [0, 1, 2, 3, 4]

    See

    • toArray - collect Stream elements into an Array
  • Generates a Stream by applying a function to the previous value, starting with the initial value. The Stream will never be exhausted.

    If try to consume the Stream, it will run forever. You can use the Stream.take method to limit the number of elements.

    Type Parameters

    • T

      The type of the elements in the Stream

    Parameters

    • init: T

      The initial value

    • fn: UnaryOperator<T>

      The function to apply to the previous value to get the next value

    Returns Stream<T>

    A Stream of the generated values

    Throws

    Example: Infinite Stream of powers of 2

    for(const x of Stream.iterate(1, (x) => x * 2)) {
    console.log(x);
    if (x > 100) break;
    }
    // Output: 1 2 4 8 16 32 64 128
  • Creates a stream from the variadic arguments.

    Type Parameters

    • T

      The type of the elements in the Stream

    Parameters

    • Rest ...values: T[]

      The values to create the Stream from

    Returns Stream<T>

    A Stream of the values

    Example: Create a Stream from variadic arguments

    const s = Stream.of(1, 2, 3, 4, 5);
    console.log(s.toArray()); // [1, 2, 3, 4, 5]

    Example: Create a Stream with spread syntax

    const s = Stream.of(..."hello");
    console.log(s.toArray()); // ["h", "e", "l", "l", "o"]

    See

  • Parameters

    • stop: number

      The end of the range

    Returns Stream<number>

    A Stream of numbers from 0 to stop (exclusive)

    Throws

    Example: Create a Stream of numbers in range [0, 5)

    const s = Stream.range(5);
    console.log(s.toArray()); // [0, 1, 2, 3, 4]

    See

  • Parameters

    • start: number

      The start of the range

    • stop: number

      The end of the range

    • Optional step: number

      The step between each number in the range

    Returns Stream<number>

    • A Stream of numbers from start to stop (exclusive) with a step of step, if step is positive.

    • A Stream of numbers from stop down to start (exclusive) with a step of step, if step is negative.

    • Empty Stream if start and stop are equal.

    Throws

    Example: Create a Stream of numbers in range [1, 6)

    const s = Stream.range(1, 6);
    console.log(s.toArray()); // [1, 2, 3, 4, 5]

    Example: Create a Stream of numbers in range [1, 6) with a step of 2

    const s = Stream.range(1, 6, 2);
    console.log(s.toArray()); // [1, 3, 5]

    Example: Create a Stream of numbers in range [5, 0)

    const s = Stream.range(5, 0, -1);
    console.log(s.toArray()); // [5, 4, 3, 2, 1]

    Example: Stream would be empty without the step

    const s = Stream.range(5, 0);
    console.log(s.toArray()); // []
  • Repeats a value indefinitely. The Stream will never be exhausted. If try to consume the Stream, it will run forever. You can use the Stream.take method to limit the number of elements.

    Type Parameters

    • T

      The type of the elements in the Stream

    Parameters

    • value: T

      The value to repeat

    Returns Stream<T>

    A Stream of the repeated value

    Throws

    Example: Infinite Stream of 1s

    for(const x of Stream.repeat(1)) {
    console.log(x);
    }
    // Output: 1 1 1 1 1 ...

    Example: Take the first 5 elements of the infinite Stream

    const s = Stream.repeat(5).take(5);
    console.log(s.toArray()); // [5, 5, 5, 5, 5]

    See

    • Stream.take - take up to n of elements first elements of the Stream
  • Creates a new Stream by zipping together the elements of the iterables.

    The resulting Stream will contain tuples of the elements of the original iterables. The resulting Stream will have the length of the shortest iterable.

    Type Parameters

    • T extends any[]

      The type of the elements in the original Stream

    Parameters

    • Rest ...iterables: {
          [I in string | number | symbol]: Iterable<T[I]>
      }

      Iterables to zip together

    Returns Stream<T>

    A new Stream containing tuples of the elements of the original iterables

    Throws

    Example: Zip two Streams together

    const s1 = Stream.range(5);
    const s2 = Stream.range(5, 10);
    const s = Stream.zip(s1, s2);
    console.log(s.toArray()); // [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]

    See

Terminators

  • Checks if all the elements in the Stream are true. It is a short-circuiting operation, meaning that it will stop as soon as it finds a false element.

    Parameters

    Returns boolean

    • true if the Stream is empty
    • true if all the elements in the Stream are true, false otherwise

    Throws

    Example: Check if all the elements in an array are even

    const s = Stream.range(5)
    .filter(x => x % 2 === 0)
    .map(x => x % 2 === 0);
    console.log(s.all()); // true

    See

  • Checks if all the elements in the Stream satisfy the predicate. This is similar to Stream.all, but it uses a predicate to check the elements. It is a short-circuiting operation, meaning that it will stop as soon as it finds an element that does not satisfy the predicate.

    This operation is equivalent to calling Stream.map with and then Stream.all.

    Parameters

    • this: Stream<T>
    • fn: ((x) => boolean)

      The function to apply to each element in the Stream

        • (x): boolean
        • Parameters

          Returns boolean

    Returns boolean

    • true if the Stream is empty
    • true if all the elements in the Stream satisfy the predicate, false otherwise

    Throws

    Example: Check if all the elements in a Stream are even

    const s = Stream.range(5).filter(x => x % 2 === 0);
    console.log(s.allMap(x => x % 2 === 0)); // true

    See

  • Checks if any of the elements in the Stream are true. It is a short-circuiting operation, meaning that it will stop as soon as it finds a true element.

    Parameters

    Returns boolean

    • false if the Stream is empty
    • trueif any of the elements in the Stream aretrue, false` otherwise

    Throws

    Example: Check if any of the elements in an array are even

    const s = Stream.range(5)
    .filter(x => x % 2 === 0)
    .map(x => x % 2 === 0);
    console.log(s.any()); // true

    See

  • Checks if any of the elements in the Stream satisfy the predicate. This is similar to Stream.any, but it uses a predicate to check the elements. It is a short-circuiting operation, meaning that it will stop as soon as it finds an element that satisfies the predicate.

    This operation is equivalent to calling Stream.map with and then Stream.any.

    Parameters

    • this: Stream<T>
    • fn: ((x) => boolean)

      The function to apply to each element in the Stream

        • (x): boolean
        • Parameters

          Returns boolean

    Returns boolean

    • false if the Stream is empty
    • true if any of the elements in the Stream satisfy the predicate, false otherwise

    Throws

    Example: Check if any of the elements in a Stream are odd

    const s = Stream.range(5).filter(x => x % 2 === 0);
    console.log(s.anyMap(x => x % 2 === 0)); // false

    See

  • Compares the elements of the Stream with the elements of another Stream. The comparison is done lexicographically, that is, the first elements of each Stream are compared, then the second elements, and so on.

    Type Parameters

    • U

      The type of the elements in the other Stream

    Parameters

    Returns -1 | 0 | 1

    • 0 if this Stream is equal to the other Stream
    • -1 if this Stream is less than the other Stream
    • 1 if this Stream is greater than the other Stream

    Throws

    Example: Compare two equal Streams

    const s1 = Stream.range(5);
    const s2 = Stream.range(5);
    console.log(s1.compare(s2)); // 0

    Example: Compare two Streams of letters

    const s1 = Stream.from("aab");
    const s2 = Stream.from("abb");
    console.log(s1.compare(s2)); // -1

    See

  • Compares the elements of the Stream with the elements of another Stream using a key function to map the elements to a comparable value.

    Behaves like Stream.compare, but uses a key function to map the elements to a comparable value.

    Type Parameters

    • U

      The type of the elements in the other Stream

    Parameters

    • this: Stream<T>
    • other: Stream<T>

      The other Stream to compare with

    • fn: Function<T, U>

      The function to extract the key by which to compare the elements

    Returns -1 | 0 | 1

    • 0 if this Stream is equal to the other Stream
    • -1 if this Stream is less than the other Stream
    • 1 if this Stream is greater than the other Stream

    Throws

    Example: Compare two Streams of strings by length

    const s1 = Stream.from(["a", "aa", "aaa"]);
    const s2 = Stream.from(["aa", "aaa", "aaaa"]);
    console.log(s1.compareBy(s2, x => x.length)); // -1

    See

  • Counts the elements in the Stream.

    Returns number

    The number of elements in the Stream

    Throws

    Example: Count the elements in a Stream

    const s = Stream.range(5);
    console.log(s.count()); // 5

    Example: Count the elements that satisfy a predicate

    const s = Stream.range(5).filter(x => x % 2 === 0);
    console.log(s.count()); // 3

    See

  • Checks if the elements of the Stream are equal to the elements of another Stream by comparing the elements using a key function.

    Type Parameters

    • U

    Parameters

    • other: Stream<T>

      The other Stream to compare with

    • fn: Function<T, U>

      The function to extract the key by which to compare the elements

    Returns boolean

    true if the Streams are equal, false otherwise

    Throws

    Example: Check if two Streams of strings are equal by length

    const s1 = Stream.from(["a", "aa", "aaa"]);
    const s2 = Stream.from(["aa", "aaa", "aaaa"]);
    console.log(s1.eqBy(s2, x => x.length)); // false

    See

  • Finds the first element in the Stream that satisfies the predicate. If no element satisfies the predicate, returns undefined.

    Parameters

    • predicate: ((x) => boolean)

      The function to apply to each element in the Stream

        • (x): boolean
        • Parameters

          Returns boolean

    Returns undefined | T

    The first element in the Stream that satisfies the predicate, or undefined if no element satisfies the predicate

    Throws

    Example: Find the first prime number larger than 20

    const isPrime = require('is-prime-number'); // npm install is-prime-number
    const x = Stream.range(20, Infinity).findFirst(isPrime);
    console.log(x); // 23

    See

  • Finds the last element in the Stream that satisfies the predicate. If no element satisfies the predicate, returns undefined.

    Parameters

    • predicate: ((x) => boolean)

      The function to apply to each element in the Stream

        • (x): boolean
        • Parameters

          Returns boolean

    Returns undefined | T

    The last element in the Stream that satisfies the predicate, or undefined if no element satisfies the predicate

    Throws

    Example: Find the last prime number smaller than 20

    const isPrime = require('is-prime-number'); // npm install is-prime-number
    const x = Stream.range(20).findLast(isPrime);
    console.log(x); // 19

    See

  • Performs a reduction on the elements of the Stream using the fn function.

    Type Parameters

    • U

      The type of the accumulator

    Parameters

    • initial: U

      The initial value of the accumulator

    • fn: BiFunction<U, T, U>

      The function to apply to each element in the Stream and the accumulator. For each element, the function is called with the accumulator and the element as arguments.

    Returns U

    The result of the reduction

    Throws

    Remarks

    This is a terminal operation, meaning that it consumes the Stream. If the Stream is infinite, this will produce an infinite loop.

    Example: Sum the elements in a Stream

    const s = Stream.range(5);
    console.log(s.fold(0, (acc, x) => acc + x)); // 10

    Example: Multiply the elements in a Stream

    const s = Stream.range(1, 6);
    console.log(s.fold(1, (acc, x) => acc * x)); // 120

    Example: Aggregate key-value pairs in a Stream into an object

    const s = Stream.from([["a", 1], ["b", 2], ["c", 3]]);
    console.log(s.fold({}, (acc, [k, v]) => ({...acc, [k]: v}))); // { a: 1, b: 2, c: 3 }

    See

    • Similar operations
    • Mentioned in examples
  • Calls a function for each element in the Stream.

    Parameters

    • fn: Consumer<T>

      The function to call for each element in the Stream

    Returns void

    Throws

    Example: Print the elements in a Stream

    const s = Stream.range(5);
    s.forEach(console.log);
    // Output:
    // 0
    // 1
    // 2
    // 3
    // 4

    See

  • Checks if the elements of the Stream are sorted in ascending order.

    Type Parameters

    • U

    Parameters

    • this: Stream<T>
    • reverse: boolean = false

      If true, checks if the elements are sorted in descending order

    • Optional key: Function<T, U>

      A function to extract the key by which to compare the elements

    Returns boolean

    true if the elements are sorted, false otherwise

    Throws

    Example: Check if a Stream is sorted

    const s = Stream.range(5);
    console.log(s.isSorted()); // true

    Example: Check if a Stream of strings is sorted by length

    const s = Stream.from(["a", "aa", "aaa"]);
    console.log(s.isSorted(false, s=> s.length)); // true

    Example: Check if a Stream is sorted in descending order

    const s = Stream.range(5, 0, -1);
    console.log(s.isSorted(true)); // true

    See

  • Checks if the elements of the Stream are sorted in ascending order.

    Parameters

    • this: Stream<T>
    • fn: Comparator<T>

      A function to compare the elements

    • reverse: boolean = false

      If true, checks if the elements are sorted in descending order

    Returns boolean

    true if the elements are sorted, false otherwise

    Throws

    Example: Check if a Stream is sorted

    const s = Stream.from(["a", "aa", "aaa"]);
    console.log(s.isSortedBy((s1, s2) => s1.length - s2.length)); // true

    See

  • Joins the elements of the Stream into a single string, similar to the Array.prototype.join method.

    Parameters

    • this: Stream<string>
    • separator: string = ""

      The separator to use between the elements

    Returns string

    A string containing the elements of the Stream

    Throws

    Example: Join the elements in a Stream

    const s = Stream.from(["a", "b", "c"]);
    console.log(s.join()); // "abc"

    Example: Join the elements in a Stream with a separator

    const s = Stream.from(["a", "b", "c"]);
    console.log(s.join("-")); // "a-b-c"

    See

  • Finds the maximum element in the Stream.

    Parameters

    Returns undefined | number

    The maximum element in the Stream

    Throws

    Example: Find the maximum element in a Stream

    const s = Stream.range(5);
    console.log(s.max()); // 4

    See

  • Finds the minimum element in the Stream.

    Parameters

    Returns undefined | number

    The minimum element in the Stream

    Throws

    Example: Find the minimum element in a Stream

    const s = Stream.range(5);
    console.log(s.min()); // 0

    See

  • Multiplies the elements of the Stream of numbers.

    Parameters

    Returns number

    • The product of the elements in the Stream if the Stream is not empty
    • 1 if the Stream is empty

    Throws

    Example: Multiply the first 5 numbers

    const s = Stream.range(1, 6);
    console.log(s.product()); // 120

    See

  • Reduction operation that reduces the elements of the Stream to a single value. It is similar to Stream.fold, but it does not require an initial value. Instead, it uses the first element of the Stream as the initial value.

    Parameters

    • fn: BiOperator<T>

      The function to apply to each element in the Stream and the accumulator. For each element, the function is called with the accumulator and the element as arguments.

    Returns undefined | T

    • The result of the reduction, if the Stream is not empty
    • undefined if the Stream is empty

    Throws

    Example: Sum the elements in a Stream

    const s = Stream.range(5);
    console.log(s.reduce((acc, x) => acc + x)); // 10

    Example: Factorial of n

    function factorial(n: number) {
    return Stream.range(n, 0, -1).reduce((acc, x) => acc * x);
    }

    console.log(factorial(5)); // 120

    See

    • Similar operations
      • Stream.fold - Similar to 'reduce' but with an initial value
    • Mentioned in examples
  • Adds the elements of the Stream of numbers.

    Parameters

    Returns number

    • The sum of the elements in the Stream if the Stream is not empty
    • 0 if the Stream is empty

    Throws

    Example: Sum the first 10 odd numbers

    const s = Stream.range(1, 20, 2);
    console.log(s.sum()); // 100

    See

Transformers

  • Chains the elements of the Stream with the elements of another iterable. The resulting Stream will contain all the elements of the original Stream, followed by the elements of the other iterable.

    Type Parameters

    • U

      The type of the elements in the other iterable

    Parameters

    • iterable: Iterable<U>

      The other iterable to chain with

    Returns Stream<T | U>

    A new Stream containing all the elements of the original Stream, and the elements of the other iterable

    Throws

    Example: Chain a Stream with an array

    const s = Stream.range(3).chain([3, 4, 5]);
    console.log(s.toArray()); // [0, 1, 2, 3, 4, 5]

    See

  • Creates a new stream by chunking the elements of the original Stream into chunks of size n. The resulting Stream will contain arrays of the elements of the original Stream. The last chunk may contain fewer than n elements.

    Parameters

    • this: Stream<T>
    • n: number

      The size of each chunk

    Returns Stream<T[]>

    A new Stream containing arrays of the elements of the original Stream

    Throws

    Example: Chunk a Stream into arrays of size 3

    const s = Stream.range(10).chunk(3);
    console.log(s.toArray()); // [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]

    Example: Chunk a Stream into arrays of size 2

    const s = Stream.range(9).chunk(2);
    console.log(s.toArray()); // [[0, 1], [2, 3], [4, 5], [6, 7], [8]]

    @ see

  • Enumerates the elements in the Stream. This is useful for getting the index of each element.

    Transforms the Stream of elements into a Stream of tuples, where the first element of the tuple is the index

    Returns Stream<[number, T]>

    A new Stream of tuples, where the first element of the tuple is the index

    Throws

    Example: Enumerate the elements in a Stream

    const s = Stream.from('abc').enumerate();
    console.log(s.toArray()); // [[0, "a"], [1, "b"], [2, "c"]]

    See

  • Creates a new Stream containing only the elements of the original Stream that satisfy the predicate.

    Parameters

    • predicate: Predicate<T>

      The function to apply to each element in the Stream

    Returns Stream<T>

    A new Stream where each element of type U

    Throws

    Example: Map the elements in a Stream with index

    const s = Stream.range(5).filter(x => x % 2 === 0);
    console.log(s.toArray()); // [0, 2, 4]

    See

  • Flattens a Stream of iterables into a single Stream. This is useful for flattening a Stream of Streams, or a Stream of arrays. The resulting Stream will contain all the elements of the original Stream of iterables. The order of the elements is preserved.

    Type Parameters

    • U

      The type of the elements in the iterables

    Parameters

    Returns Stream<U>

    A new Stream containing all the elements of the original Stream of iterables

    Throws

    Example: Flatten a Stream of arrays

    const s = Stream.from([[1, 2], [3, 4], [5, 6]]);
    console.log(s.flatten().toArray()); // [1, 2, 3, 4, 5, 6]

    Example: Flatten a Stream of Streams

    const s = Stream.range(1, 4).map((x) => Stream.range(x));
    console.log(s.flatten().toArray()); // [0, 0, 1, 0, 1, 2]

    See

  • Creates a new Stream where each element is the result of applying the function fn to each element in the original Stream.

    Type Parameters

    • U

      The type of the elements in the new Stream

    Parameters

    • fn: Function<T, U>

      The function to apply to each element in the Stream

    Returns Stream<U>

    A new Stream where each element of type U

    Throws

    Example: Map the elements in a Stream

    const s = Stream.range(5).map(x => x * 2);
    console.log(s.toArray()); // [0, 2, 4, 6, 8]

    Example: Map the elements in a Stream of strings

    const s = Stream.from("hello").map(x => x.toUpperCase());
    console.log(s.toArray()); // ["H", "E", "L", "L", "O"]

    See

  • Creates a new Stream with the first n elements of the original Stream skipped. If the number of elements in the Stream is less than n, the new Stream will be empty.

    Parameters

    • n: number

      The number of elements to skip

    Returns Stream<T>

    A new Stream with the first n elements of the original Stream skipped.

    Throws

    Example: Skip the first 3 elements of a Stream

    const s = Stream.range(5).skip(3);
    console.log(s.toArray()); // [3, 4]

    See

    • Similar operations
      • Stream.take - take the first n elements of the Stream
    • Mentioned in examples
  • Creates a new Stream by sliding a window of size n over the elements of the original Stream, with a step of step. The resulting Stream will contain arrays of the elements of the original Stream.

    Parameters

    • this: Stream<T>
    • n: number

      The size of the window

    Returns Stream<T[]>

    A new Stream containing arrays of the elements of the original Stream

    Throws

    Example: Slide a window of size 3 over a Stream

    const s = Stream.range(5).slide(3);
    console.log(s.toArray()); // [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

    See

  • Creates a new Stream with the first n elements of the original Stream.

    Parameters

    • n: number

      The number of elements to take

    Returns Stream<T>

    A new Stream with the first n elements of the original Stream.

    Throws

    Example: Take the first 3 elements of a Stream

    const s = Stream.range(5).take(3);
    console.log(s.toArray()); // [0, 1, 2]

    See

  • Creates a new Stream that contains all the elements of the original Stream, before the first element that does not satisfy the predicate.

    Parameters

    • predicate: Predicate<T>

      Function used to test each element in the Stream

    Returns Stream<T>

    A new Stream that contains all the elements of the original Stream,

    Throws

    Example: Take the elements of a Stream while they are less than 3

    const s = Stream.range(5).takeWhile(x => x < 3);
    console.log(s.toArray()); // [0, 1, 2]

    See

    • Similar operations
      • Stream.take - take the first n elements of the Stream
    • Mentioned in examples

Generated using TypeDoc