Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StreamStatic

Holds the "static methods" for Stream

Hierarchy

  • StreamStatic

Index

Methods

continually

  • Build an infinite stream by calling repeatedly a function.

    Stream.continually(() => 1).take(4);
    => Stream.of(1,1,1,1)
    
    Stream.continually(Math.random).take(2);
    => Stream.of(0.49884723907769635, 0.3226548779864311)
    

    Type parameters

    • T

    Parameters

    • fn: function
        • (): T
        • Returns T

    Returns ConsStream<T>

empty

isEmpty

  • isEmpty<T>(s: Stream<T>): boolean

isNotEmpty

  • isNotEmpty<T>(s: Stream<T>): boolean

iterate

  • iterate<T>(seed: T, fn: function): ConsStream<T>
  • Build an infinite stream from a seed and a transformation function.

    Stream.iterate(1, x => x*2).take(4);
    => Stream.of(1,2,4,8)
    

    Type parameters

    • T

    Parameters

    • seed: T
    • fn: function
        • (v: T): T
        • Parameters

          • v: T

          Returns T

    Returns ConsStream<T>

of

  • Create a Stream with the elements you give.

    Type parameters

    • T

    Parameters

    • elt: T
    • Rest ...elts: T[]

    Returns ConsStream<T>

  • Type parameters

    • T

    Parameters

    • Rest ...elts: T[]

    Returns Stream<T>

ofIterable

  • ofIterable<T>(elts: Iterable<T>): Stream<T>
  • Build a stream from any iterable, which means also an array for instance.

    Type parameters

    • T

      the item type

    Parameters

    • elts: Iterable<T>

    Returns Stream<T>

unfoldRight

  • unfoldRight<T, U>(seed: T, fn: function): Stream<U>
  • Dual to the foldRight function. Build a collection from a seed. Takes a starting element and a function. It applies the function on the starting element; if the function returns None, it stops building the list, if it returns Some of a pair, it adds the first element to the result and takes the second element as a seed to keep going.

    Stream.unfoldRight(
         10, x=>Option.of(x)
             .filter(x => x!==0)
             .map<[number,number]>(x => [x,x-1]));
    => Stream.of(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
    

    Type parameters

    • T

    • U

    Parameters

    • seed: T
    • fn: function
        • Parameters

          • x: T

          Returns Option<[U, T]>

    Returns Stream<U>

zip

  • Combine any number of iterables you give in as parameters to produce a new collection which combines all, in tuples. For instance:

    Stream.zip(Stream.of(1,2,3), ["a","b","c"], LinkedList.of(8,9,10))
    => Stream.of([1,"a",8], [2,"b",9], [3,"c",10])
    

    The result collection will have the length of the shorter of the input iterables. Extra elements will be discarded.

    Also see the non-static version ConsStream.zip, which only combines two collections.

    Type parameters

    • A: any[]

      A is the type of the tuple that'll be generated ([number,string,number] for the code sample)

    Parameters

    Returns Stream<A>

Generated using TypeDoc