Package fj.data

Class Stream<A>

  • All Implemented Interfaces:
    java.lang.Iterable<A>
    Direct Known Subclasses:
    Stream.Cons, Stream.Nil

    public abstract class Stream<A>
    extends java.lang.Object
    implements java.lang.Iterable<A>
    A lazy (not yet evaluated), immutable, singly linked list.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Stream.Cons<A>  
      private static class  Stream.Nil<A>  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Stream()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Stream<A> append​(Stream<A> as)
      Appends the given stream to this stream.
      Stream<A> append​(F0<Stream<A>> as)
      Appends the given stream to this stream.
      <B> Stream<B> apply​(Stream<F<A,​B>> sf)
      Performs function application within a stream (applicative functor pattern).
      A[] array​(java.lang.Class<A[]> c)
      Returns an array from this stream.
      static <A> Stream<A> arrayStream​(A... as)  
      static java.lang.String asString​(Stream<java.lang.Character> cs)
      Returns a string from the given stream of characters.
      <B,​C,​D,​E,​F$,​G,​H,​I>
      Stream<I>
      bind​(Stream<B> sb, Stream<C> sc, Stream<D> sd, Stream<E> se, Stream<F$> sf, Stream<G> sg, Stream<H> sh, F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​F<H,​I>>>>>>>> f)
      Binds the given function across each element of this stream and the given streams with a final join.
      <B,​C,​D,​E,​F$,​G,​H>
      Stream<H>
      bind​(Stream<B> sb, Stream<C> sc, Stream<D> sd, Stream<E> se, Stream<F$> sf, Stream<G> sg, F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​H>>>>>>> f)
      Binds the given function across each element of this stream and the given streams with a final join.
      <B,​C,​D,​E,​F$,​G>
      Stream<G>
      bind​(Stream<B> sb, Stream<C> sc, Stream<D> sd, Stream<E> se, Stream<F$> sf, F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​G>>>>>> f)
      Binds the given function across each element of this stream and the given streams with a final join.
      <B,​C,​D,​E,​F$>
      Stream<F$>
      bind​(Stream<B> sb, Stream<C> sc, Stream<D> sd, Stream<E> se, F<A,​F<B,​F<C,​F<D,​F<E,​F$>>>>> f)
      Binds the given function across each element of this stream and the given streams with a final join.
      <B,​C,​D,​E>
      Stream<E>
      bind​(Stream<B> sb, Stream<C> sc, Stream<D> sd, F<A,​F<B,​F<C,​F<D,​E>>>> f)
      Binds the given function across each element of this stream and the given streams with a final join.
      <B,​C,​D>
      Stream<D>
      bind​(Stream<B> sb, Stream<C> sc, F<A,​F<B,​F<C,​D>>> f)
      Binds the given function across each element of this stream and the given streams with a final join.
      <B,​C>
      Stream<C>
      bind​(Stream<B> sb, F<A,​F<B,​C>> f)
      Binds the given function across each element of this stream and the given stream with a final join.
      <B,​C>
      Stream<C>
      bind​(Stream<B> sb, F2<A,​B,​C> f)
      Binds the given function across each element of this stream and the given stream with a final join.
      <B> Stream<B> bind​(F<A,​Stream<B>> f)
      Binds the given function across each element of this stream with a final join.
      static <A,​B>
      F<F<A,​Stream<B>>,​F<Stream<A>,​Stream<B>>>
      bind_()
      A first-class version of the bind function.
      <B> Stream<B> cobind​(F<Stream<A>,​B> k)
      Binds the given function across the stream of substreams of this stream.
      static <A> F<A,​F<P1<Stream<A>>,​Stream<A>>> cons()
      Returns a function that prepends (cons) an element to a stream to produce a new stream.
      Stream<A> cons​(A a)
      Prepends (cons) the given element to this stream to product a new stream.
      static <A> Stream<A> cons​(A head, F0<Stream<A>> tail)
      Prepends the given head element to the given tail element to produce a new stream.
      static <A> F<A,​F<Stream<A>,​Stream<A>>> cons_()
      Returns a function that prepends (cons) an element to a stream to produce a new stream.
      static <A> Stream<A> cycle​(Stream<A> as)
      Returns an infinite-length stream of the given elements cycling.
      Stream<A> drop​(int i)
      Drops the given number of elements from the head of this stream if they are available.
      Stream<A> dropWhile​(F<A,​java.lang.Boolean> f)
      Removes elements from the head of this stream that do not match the given predicate function until an element is found that does match or the stream is exhausted.
      static <A> Stream<A> enumerationStream​(java.util.Enumeration<A> e)  
      boolean equals​(java.lang.Object other)  
      boolean exists​(F<A,​java.lang.Boolean> f)
      Returns true if the predicate holds for at least one of the elements of this stream, false otherwise (false for the empty stream).
      static <A> F<F<A,​java.lang.Boolean>,​F<Stream<A>,​Stream<A>>> filter()
      Returns a first-class version of the filter function.
      Stream<A> filter​(F<A,​java.lang.Boolean> f)
      Filters elements from this stream by returning only elements which produce true when the given function is applied to them.
      Option<A> find​(F<A,​java.lang.Boolean> f)
      Finds the first occurrence of an element that matches the given predicate or no value if no elements match.
      private static <A> F<Stream<A>,​Promise<Stream<A>>> flt​(Ord<A> o, Strategy<Unit> s, A x, F<java.lang.Boolean,​java.lang.Boolean> f)  
      <B> B foldLeft​(F<B,​F<A,​B>> f, B b)
      Performs a left-fold reduction across this stream.
      <B> B foldLeft​(F2<B,​A,​B> f, B b)
      Performs a left-fold reduction across this stream.
      A foldLeft1​(F<A,​F<A,​A>> f)
      Takes the first 2 elements of the stream and applies the function to them, then applies the function to the result and the third element and so on.
      A foldLeft1​(F2<A,​A,​A> f)
      Takes the first 2 elements of the stream and applies the function to them, then applies the function to the result and the third element and so on.
      static <A,​B>
      F<F<A,​F<P1<B>,​B>>,​F<B,​F<Stream<A>,​B>>>
      foldRight()
      A first-class version of the foldRight function.
      <B> B foldRight​(F<A,​F<P1<B>,​B>> f, B b)
      Performs a right-fold reduction across this stream.
      <B> B foldRight​(F2<A,​P1<B>,​B> f, B b)
      Performs a right-fold reduction across this stream.
      <B> B foldRight1​(F<A,​F<B,​B>> f, B b)
      Performs a right-fold reduction across this stream.
      <B> B foldRight1​(F2<A,​B,​B> f, B b)
      Performs a right-fold reduction across this stream.
      boolean forall​(F<A,​java.lang.Boolean> f)
      Returns true if the predicate holds for all of the elements of this stream, false otherwise (true for the empty stream).
      Unit foreach​(F<A,​Unit> f)
      Performs a side-effect for each element of this stream.
      void foreachDoEffect​(Effect1<A> f)
      Performs a side-effect for each element of this stream.
      static <A> Stream<A> forever​(Enumerator<A> e, A from)
      Returns a stream that is either infinite or bounded up to the maximum value of the given iterator starting at the given value and stepping at increments of 1.
      static <A> Stream<A> forever​(Enumerator<A> e, A from, long step)
      Returns a stream that is either infinite or bounded up to the maximum value of the given iterator starting at the given value and stepping at the given increment.
      static <A,​B>
      Stream<A>
      fromFunction​(Enumerator<B> e, F<B,​A> f, B i)
      Converts a function of an enumerable type to a stream of the results of that function, starting at the given index.
      static <A> Stream<A> fromFunction​(F<Natural,​A> f)
      Converts a function of natural numbers to a stream.
      static Stream<java.lang.Character> fromString​(java.lang.String s)
      Returns a stream of characters from the given string.
      int hashCode()  
      abstract A head()
      The first element of the stream or fails for the empty stream.
      A index​(int i)
      Returns the element at the given index if it exists, fails otherwise.
      Option<java.lang.Integer> indexOf​(F<A,​java.lang.Boolean> p)
      Returns the position of the first element matching the given predicate, if any.
      Stream<Stream<A>> inits()
      Returns a stream of all prefixes of this stream.
      Stream<A> interleave​(Stream<A> as)
      Interleaves the given stream with this stream to produce a new stream.
      Stream<A> intersperse​(A a)
      Intersperses the given value between each two elements of the stream.
      boolean isEmpty()
      Returns true if this stream is empty, false otherwise.
      static <A> F<Stream<A>,​java.lang.Boolean> isEmpty_()
      Returns a function that determines whether a given stream is empty.
      boolean isNotEmpty()
      Returns false if this stream is empty, true otherwise.
      static <A> F<Stream<A>,​java.lang.Boolean> isNotEmpty_()
      Returns a function that determines whether a given stream is not empty.
      static <A> Stream<A> iterableStream​(java.lang.Iterable<A> i)
      Takes the given iterable to a stream.
      static <A> F<F<A,​A>,​F<A,​Stream<A>>> iterate()
      A first-class version of the iterate function.
      static <A> Stream<A> iterate​(F<A,​A> f, A a)
      Returns a stream constructed by applying the given iteration function starting at the given value.
      static <A> Stream<A> iterateWhile​(F<A,​A> f, F<A,​java.lang.Boolean> p, A a)
      Creates a stream where the first item is calculated by applying the function on the third argument, the second item by applying the function on the previous result and so on.
      java.util.Iterator<A> iterator()
      Returns an iterator for this stream.
      static <A> Stream<A> iteratorStream​(java.util.Iterator<A> it)
      Constructs a stream with the given elements in the Iterator.
      static <A> F<Stream<Stream<A>>,​Stream<A>> join()
      A first-class version of join
      static <A> Stream<A> join​(Stream<Stream<A>> o)
      Joins the given stream of streams by concatenation.
      A last()
      Get the last element of this stream.
      int length()
      The length of this stream.
      <B> Stream<B> map​(F<A,​B> f)
      Maps the given function across this stream.
      static <A,​B>
      F<F<A,​B>,​F<Stream<A>,​Stream<B>>>
      map_()
      Provides a first-class version of the map function.
      <B,​C>
      F<B,​Stream<C>>
      mapM​(F<A,​F<B,​C>> f)
      Maps the given function of arity-2 across this stream and returns a function that applies all the resulting functions to a given argument.
      private static <A> Stream<A> merge​(Ord<A> o, Stream<A> xs, Stream<A> ys)  
      private static <A> Stream<Stream<A>> mergePairs​(Ord<A> o, Stream<Stream<A>> s)  
      private static <A> Stream<A> mergesort​(Ord<A> o, Stream<Stream<A>> s)  
      Stream<A> minus​(Equal<A> eq, Stream<A> xs)
      Returns a new stream of all the items in this stream that do not appear in the given stream.
      static <A> Stream<A> nil()
      Returns an empty stream.
      static <A> P1<Stream<A>> nil_()
      Returns an empty stream.
      A orHead​(F0<A> a)
      Returns the head of this stream if there is one or the given argument if this stream is empty.
      P1<Stream<A>> orTail​(F0<Stream<A>> as)
      Returns the tail of this stream if there is one or the given argument if this stream is empty.
      private Promise<Stream<A>> qs​(Ord<A> o, Strategy<Unit> s)  
      private static <A> F<Stream<A>,​Promise<Stream<A>>> qs_​(Ord<A> o, Strategy<Unit> s)  
      static Stream<java.lang.Integer> range​(int from)
      Returns an infinite stream of integers from the given from value (inclusive).
      static Stream<java.lang.Integer> range​(int from, long to)
      Returns a stream of integers from the given from value (inclusive) to the given to value (exclusive).
      static <A> Stream<A> range​(Enumerator<A> e, A from, A to)
      Returns a stream using the given enumerator from the given value to the other given value stepping at increments of 1.
      static <A> Stream<A> range​(Enumerator<A> e, A from, A to, long step)
      Returns a stream using the given enumerator from the given value to the other given value stepping at the given increment.
      Stream<A> removeAll​(F<A,​java.lang.Boolean> f)
      Filters elements from this stream by returning only elements which produce false when the given function is applied to them.
      static <A> Stream<A> repeat​(A a)
      Returns an infinite-length stream of the given element.
      Stream<A> replace​(F<A,​java.lang.Boolean> p, A a)
      Returns a new stream resulting from replacing all elements that match the given predicate with the given element.
      Stream<A> reverse()
      Reverse this stream in constant stack space.
      static <A> Stream<IO<A>> sequence​(IO<Stream<A>> io)
      Sequence through the Stream monad.
      static <A> Stream<Option<A>> sequence​(Option<Stream<A>> o)
      Sequence through the Stream monad.
      <B> Stream<B> sequence​(Stream<B> bs)
      Performs a bind across each stream element, but ignores the element value each time.
      static <A> Stream<P1<A>> sequence​(F0<Stream<A>> p)
      Sequence through the Stream monad.
      static <A,​B>
      F<B,​Stream<A>>
      sequence_​(Stream<F<B,​A>> fs)
      Turn a stream of functions into a function returning a stream.
      static <L,​B>
      Either<L,​Stream<B>>
      sequenceEither​(Stream<Either<L,​B>> stream)
      Sequence the given stream and collect the output on the right side of an either.
      static <R,​B>
      Either<Stream<B>,​R>
      sequenceEitherLeft​(Stream<Either<B,​R>> stream)
      Sequence the given stream and collect the output on the left side of an either.
      static <L,​B>
      Either<L,​Stream<B>>
      sequenceEitherRight​(Stream<Either<L,​B>> stream)
      Sequence the given stream and collect the output on the right side of an either.
      static <C,​B>
      F<C,​Stream<B>>
      sequenceF​(Stream<F<C,​B>> stream)
      Sequence the given stream and collect the output as a function.
      static <B> IO<Stream<B>> sequenceIO​(Stream<IO<B>> stream)
      Sequence the given stream and collect the output as an IO.
      static <B> List<Stream<B>> sequenceList​(Stream<List<B>> stream)
      Sequence the given stream and collect the output as a list.
      static <B> Option<Stream<B>> sequenceOption​(Stream<Option<B>> stream)
      Sequence the given stream and collect the output as an stream.
      static <B> P1<Stream<B>> sequenceP1​(Stream<P1<B>> stream)
      Sequence the given stream and collect the output as a P1.
      static <B> Seq<Stream<B>> sequenceSeq​(Stream<Seq<B>> stream)
      Sequence the given stream and collect the output as a seq.
      static <B> Set<Stream<B>> sequenceSet​(Ord<B> ord, Stream<Set<B>> stream)
      Sequence the given stream and collect the output as a set; use the given ord to order the set.
      static <B> Stream<Stream<B>> sequenceStream​(Stream<Stream<B>> stream)
      Sequence the given stream and collect the output as a stream.
      static <B> Trampoline<Stream<B>> sequenceTrampoline​(Stream<Trampoline<B>> stream)
      Sequence the given stream and collect the output as a trampoline.
      static <E,​B>
      Validation<E,​Stream<B>>
      sequenceValidation​(Stream<Validation<E,​B>> stream)
      Sequence the given stream and collect the output as a validation.
      static <E,​B>
      Validation<E,​Stream<B>>
      sequenceValidation​(Semigroup<E> semigroup, Stream<Validation<E,​B>> stream)
      Sequence the given stream and collect the output as a validation; use the given semigroup to reduce the errors.
      <B> Stream<B> sequenceW​(Stream<F<Stream<A>,​B>> fs)
      Applies a stream of comonadic functions to this stream, returning a stream of values.
      static <A> F<A,​Stream<A>> single()
      Returns a function that yields a stream containing its argument.
      static <A> Stream<A> single​(A a)
      Returns a stream of one element containing the given value.
      Stream<A> snoc​(A a)
      Append the given element to this stream to product a new stream.
      Stream<A> snoc​(F0<A> a)
      Append the given element to this stream to produce a new stream.
      Stream<A> sort​(Ord<A> o)
      Sort this stream according to the given ordering.
      Stream<A> sort​(Ord<A> o, Strategy<Unit> s)
      Sort this stream according to the given ordering, using a parallel Quick Sort algorithm that uses the given parallelisation strategy.
      P2<Stream<A>,​Stream<A>> span​(F<A,​java.lang.Boolean> p)
      Returns a tuple where the first element is the longest prefix of this stream that satisfies the given predicate and the second element is the remainder of the stream.
      P2<Stream<A>,​Stream<A>> split​(F<A,​java.lang.Boolean> p)
      Returns a tuple where the first element is the longest prefix of this stream that does not satisfy the given predicate and the second element is the remainder of the stream.
      static <A> Stream<A> stream​(A... as)
      Constructs a stream with the given elements.
      Stream<Stream<A>> substreams()
      Returns a stream of all infixes of this stream.
      abstract P1<Stream<A>> tail()
      The stream without the first element or fails for the empty stream.
      Stream<Stream<A>> tails()
      Returns a stream of the suffixes of this stream.
      Stream<A> take​(int n)
      Returns the first n elements from the head of this stream.
      Stream<A> takeWhile​(F<A,​java.lang.Boolean> f)
      Returns the first elements of the head of this stream that match the given predicate function.
      Array<A> toArray()
      Returns a array projection of this stream.
      Array<A> toArray​(java.lang.Class<A[]> c)
      Returns a array projection of this stream.
      java.util.Collection<A> toCollection()
      Projects an immutable collection of this stream.
      <X> Either<X,​A> toEither​(F0<X> x)
      Returns an either projection of this stream; the given argument in Left if empty, or the first element in Right.
      F<java.lang.Integer,​A> toFunction()
      Converts this stream to a function of natural numbers.
      java.util.List<A> toJavaList()
      Returns a java.util.List projection of this stream.
      List<A> toList()
      Returns a list projection of this stream.
      Option<A> toOption()
      Returns an option projection of this stream; None if empty, or the first element in Some.
      java.lang.String toString()  
      java.lang.String toStringEager()  
      java.lang.String toStringLazy()  
      <B,​L>
      Either<L,​Stream<B>>
      traverseEither​(F<A,​Either<L,​B>> f)
      Traverse this stream with the given function and collect the output on the right side of an either.
      <R,​B>
      Either<Stream<B>,​R>
      traverseEitherLeft​(F<A,​Either<B,​R>> f)
      Traverse this stream with the given function and collect the output on the left side of an either.
      <L,​B>
      Either<L,​Stream<B>>
      traverseEitherRight​(F<A,​Either<L,​B>> f)
      Traverse this stream with the given function and collect the output on the right side of an either.
      <C,​B>
      F<C,​Stream<B>>
      traverseF​(F<A,​F<C,​B>> f)
      Traverse this stream with the given function and collect the output as a function.
      <B> IO<Stream<B>> traverseIO​(F<A,​IO<B>> f)
      Traverse this stream with the given function and collect the output as an IO.
      <B> List<Stream<B>> traverseList​(F<A,​List<B>> f)
      Traverse this stream with the given function and collect the output as a list.
      <B> Option<Stream<B>> traverseOption​(F<A,​Option<B>> f)
      Traverses through the Seq with the given function
      <B> P1<Stream<B>> traverseP1​(F<A,​P1<B>> f)
      Traverse this stream with the given function and collect the output as a p1.
      <B> Seq<Stream<B>> traverseSeq​(F<A,​Seq<B>> f)
      Traverse this stream with the given function and collect the output as a seq.
      <B> Set<Stream<B>> traverseSet​(Ord<B> ord, F<A,​Set<B>> f)
      Traverse this stream with the given function and collect the output as a set; use the given ord to order the set.
      <B> Stream<Stream<B>> traverseStream​(F<A,​Stream<B>> f)
      Traverse this stream with the given function and collect the output as a stream.
      <B> Trampoline<Stream<B>> traverseTrampoline​(F<A,​Trampoline<B>> f)
      Traverse this stream with the given function and collect the output as a trampoline.
      <E,​B>
      Validation<E,​Stream<B>>
      traverseValidation​(F<A,​Validation<E,​B>> f)
      Traverse this stream with the given function and collect the output as a validation.
      <E,​B>
      Validation<E,​Stream<B>>
      traverseValidation​(Semigroup<E> semigroup, F<A,​Validation<E,​B>> f)
      Traverse this stream with the given function and collect the output as a validation; use the given semigroup to reduce the errors.
      <B> B uncons​(B nil, F<A,​F<P1<Stream<A>>,​B>> cons)
      Performs a reduction on this stream using the given arguments.
      static <A,​B>
      Stream<A>
      unfold​(F<B,​Option<P2<A,​B>>> f, B b)
      Unfolds across the given function starting at the given value to produce a stream.
      static <A,​B>
      P2<Stream<A>,​Stream<B>>
      unzip​(Stream<P2<A,​B>> xs)
      Transforms a stream of pairs into a stream of first components and a stream of second components.
      <B> Stream<B> zapp​(Stream<F<A,​B>> fs)
      Zips this stream with the given stream of functions, applying each function in turn to the corresponding element in this stream to produce a new stream.
      <B> Stream<P2<A,​B>> zip​(Stream<B> bs)
      Zips this stream with the given stream to produce a stream of pairs.
      Stream<P2<A,​java.lang.Integer>> zipIndex()
      Zips this stream with the index of its element as a pair.
      static <A,​B,​C>
      F<Stream<A>,​F<Stream<B>,​F<F<A,​F<B,​C>>,​Stream<C>>>>
      zipWith()
      A first-class version of the zipWith function.
      <B,​C>
      Stream<C>
      zipWith​(Stream<B> bs, F<A,​F<B,​C>> f)
      Zips this stream with the given stream using the given function to produce a new stream.
      <B,​C>
      Stream<C>
      zipWith​(Stream<B> bs, F2<A,​B,​C> f)
      Zips this stream with the given stream using the given function to produce a new stream.
      <B,​C>
      F<Stream<B>,​Stream<C>>
      zipWith​(F<A,​F<B,​C>> f)
      Partially-applied version of zipWith.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • Stream

        private Stream()
    • Method Detail

      • iterator

        public final java.util.Iterator<A> iterator()
        Returns an iterator for this stream. This method exists to permit the use in a for-each loop.
        Specified by:
        iterator in interface java.lang.Iterable<A>
        Returns:
        A iterator for this stream.
      • head

        public abstract A head()
        The first element of the stream or fails for the empty stream.
        Returns:
        The first element of the stream or fails for the empty stream.
      • tail

        public abstract P1<Stream<A>> tail()
        The stream without the first element or fails for the empty stream.
        Returns:
        The stream without the first element or fails for the empty stream.
      • isEmpty

        public final boolean isEmpty()
        Returns true if this stream is empty, false otherwise.
        Returns:
        true if this stream is empty, false otherwise.
      • isNotEmpty

        public final boolean isNotEmpty()
        Returns false if this stream is empty, true otherwise.
        Returns:
        false if this stream is empty, true otherwise.
      • uncons

        public final <B> B uncons​(B nil,
                                  F<A,​F<P1<Stream<A>>,​B>> cons)
        Performs a reduction on this stream using the given arguments.
        Parameters:
        nil - The value to return if this stream is empty.
        cons - The function to apply to the head and tail of this stream if it is not empty.
        Returns:
        A reduction on this stream.
      • foldRight

        public final <B> B foldRight​(F<A,​F<P1<B>,​B>> f,
                                     B b)
        Performs a right-fold reduction across this stream. This function uses O(length) stack space.
        Parameters:
        f - The function to apply on each element of the stream.
        b - The beginning value to start the application from.
        Returns:
        The final result after the right-fold reduction.
      • foldRight

        public final <B> B foldRight​(F2<A,​P1<B>,​B> f,
                                     B b)
        Performs a right-fold reduction across this stream. This function uses O(length) stack space.
        Parameters:
        f - The function to apply on each element of the stream.
        b - The beginning value to start the application from.
        Returns:
        The final result after the right-fold reduction.
      • foldRight1

        public final <B> B foldRight1​(F<A,​F<B,​B>> f,
                                      B b)
        Performs a right-fold reduction across this stream. This function uses O(length) stack space.
        Parameters:
        f - The function to apply on each element of the stream.
        b - The beginning value to start the application from.
        Returns:
        The final result after the right-fold reduction.
      • foldRight1

        public final <B> B foldRight1​(F2<A,​B,​B> f,
                                      B b)
        Performs a right-fold reduction across this stream. This function uses O(length) stack space.
        Parameters:
        f - The function to apply on each element of the stream.
        b - The beginning value to start the application from.
        Returns:
        The final result after the right-fold reduction.
      • foldLeft

        public final <B> B foldLeft​(F<B,​F<A,​B>> f,
                                    B b)
        Performs a left-fold reduction across this stream. This function runs in constant space.
        Parameters:
        f - The function to apply on each element of the stream.
        b - The beginning value to start the application from.
        Returns:
        The final result after the left-fold reduction.
      • foldLeft

        public final <B> B foldLeft​(F2<B,​A,​B> f,
                                    B b)
        Performs a left-fold reduction across this stream. This function runs in constant space.
        Parameters:
        f - The function to apply on each element of the stream.
        b - The beginning value to start the application from.
        Returns:
        The final result after the left-fold reduction.
      • foldLeft1

        public final A foldLeft1​(F2<A,​A,​A> f)
        Takes the first 2 elements of the stream and applies the function to them, then applies the function to the result and the third element and so on.
        Parameters:
        f - The function to apply on each element of the stream.
        Returns:
        The final result after the left-fold reduction.
      • foldLeft1

        public final A foldLeft1​(F<A,​F<A,​A>> f)
        Takes the first 2 elements of the stream and applies the function to them, then applies the function to the result and the third element and so on.
        Parameters:
        f - The function to apply on each element of the stream.
        Returns:
        The final result after the left-fold reduction.
      • orHead

        public final A orHead​(F0<A> a)
        Returns the head of this stream if there is one or the given argument if this stream is empty.
        Parameters:
        a - The argument to return if this stream is empty.
        Returns:
        The head of this stream if there is one or the given argument if this stream is empty.
      • orTail

        public final P1<Stream<A>> orTail​(F0<Stream<A>> as)
        Returns the tail of this stream if there is one or the given argument if this stream is empty.
        Parameters:
        as - The argument to return if this stream is empty.
        Returns:
        The tail of this stream if there is one or the given argument if this stream is empty.
      • intersperse

        public final Stream<A> intersperse​(A a)
        Intersperses the given value between each two elements of the stream.
        Parameters:
        a - The value to intersperse between values of the stream.
        Returns:
        A new stream with the given value between each two elements of the stream.
      • map

        public final <B> Stream<B> map​(F<A,​B> f)
        Maps the given function across this stream.
        Parameters:
        f - The function to map across this stream.
        Returns:
        A new stream after the given function has been applied to each element.
      • map_

        public static <A,​B> F<F<A,​B>,​F<Stream<A>,​Stream<B>>> map_()
        Provides a first-class version of the map function.
        Returns:
        A function that maps a given function across a given stream.
      • foreach

        public final Unit foreach​(F<A,​Unit> f)
        Performs a side-effect for each element of this stream.
        Parameters:
        f - The side-effect to perform for the given element.
        Returns:
        The unit value.
      • foreachDoEffect

        public final void foreachDoEffect​(Effect1<A> f)
        Performs a side-effect for each element of this stream.
        Parameters:
        f - The side-effect to perform for the given element.
      • filter

        public final Stream<A> filter​(F<A,​java.lang.Boolean> f)
        Filters elements from this stream by returning only elements which produce true when the given function is applied to them.
        Parameters:
        f - The predicate function to filter on.
        Returns:
        A new stream whose elements all match the given predicate.
      • append

        public final Stream<A> append​(Stream<A> as)
        Appends the given stream to this stream.
        Parameters:
        as - The stream to append to this one.
        Returns:
        A new stream that has appended the given stream.
      • append

        public final Stream<A> append​(F0<Stream<A>> as)
        Appends the given stream to this stream.
        Parameters:
        as - The stream to append to this one.
        Returns:
        A new stream that has appended the given stream.
      • minus

        public final Stream<A> minus​(Equal<A> eq,
                                     Stream<A> xs)
        Returns a new stream of all the items in this stream that do not appear in the given stream.
        Parameters:
        eq - an equality for the items of the streams.
        xs - a list to subtract from this stream.
        Returns:
        a stream of all the items in this stream that do not appear in the given stream.
      • removeAll

        public final Stream<A> removeAll​(F<A,​java.lang.Boolean> f)
        Filters elements from this stream by returning only elements which produce false when the given function is applied to them.
        Parameters:
        f - The predicate function to filter on.
        Returns:
        A new stream whose elements do not match the given predicate.
      • sequence_

        public static <A,​B> F<B,​Stream<A>> sequence_​(Stream<F<B,​A>> fs)
        Turn a stream of functions into a function returning a stream.
        Parameters:
        fs - The stream of functions to sequence into a single function that returns a stream.
        Returns:
        A function that, when given an argument, applies all the functions in the given stream to it and returns a stream of the results.
      • mapM

        public final <B,​C> F<B,​Stream<C>> mapM​(F<A,​F<B,​C>> f)
        Maps the given function of arity-2 across this stream and returns a function that applies all the resulting functions to a given argument.
        Parameters:
        f - A function of arity-2
        Returns:
        A function that, when given an argument, applies the given function to that argument and every element in this list.
      • bind

        public final <B> Stream<B> bind​(F<A,​Stream<B>> f)
        Binds the given function across each element of this stream with a final join.
        Parameters:
        f - The function to apply to each element of this stream.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C> Stream<C> bind​(Stream<B> sb,
                                                F<A,​F<B,​C>> f)
        Binds the given function across each element of this stream and the given stream with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given stream.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C> Stream<C> bind​(Stream<B> sb,
                                                F2<A,​B,​C> f)
        Binds the given function across each element of this stream and the given stream with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given stream.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C,​D> Stream<D> bind​(Stream<B> sb,
                                                        Stream<C> sc,
                                                        F<A,​F<B,​F<C,​D>>> f)
        Binds the given function across each element of this stream and the given streams with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        sc - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given streams.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E> Stream<E> bind​(Stream<B> sb,
                                                                Stream<C> sc,
                                                                Stream<D> sd,
                                                                F<A,​F<B,​F<C,​F<D,​E>>>> f)
        Binds the given function across each element of this stream and the given streams with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        sc - A given stream to bind the given function with.
        sd - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given streams.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$> Stream<F$> bind​(Stream<B> sb,
                                                                          Stream<C> sc,
                                                                          Stream<D> sd,
                                                                          Stream<E> se,
                                                                          F<A,​F<B,​F<C,​F<D,​F<E,​F$>>>>> f)
        Binds the given function across each element of this stream and the given streams with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        sc - A given stream to bind the given function with.
        sd - A given stream to bind the given function with.
        se - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given streams.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$,​G> Stream<G> bind​(Stream<B> sb,
                                                                                 Stream<C> sc,
                                                                                 Stream<D> sd,
                                                                                 Stream<E> se,
                                                                                 Stream<F$> sf,
                                                                                 F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​G>>>>>> f)
        Binds the given function across each element of this stream and the given streams with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        sc - A given stream to bind the given function with.
        sd - A given stream to bind the given function with.
        se - A given stream to bind the given function with.
        sf - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given streams.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$,​G,​H> Stream<H> bind​(Stream<B> sb,
                                                                                         Stream<C> sc,
                                                                                         Stream<D> sd,
                                                                                         Stream<E> se,
                                                                                         Stream<F$> sf,
                                                                                         Stream<G> sg,
                                                                                         F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​H>>>>>>> f)
        Binds the given function across each element of this stream and the given streams with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        sc - A given stream to bind the given function with.
        sd - A given stream to bind the given function with.
        se - A given stream to bind the given function with.
        sf - A given stream to bind the given function with.
        sg - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given streams.
        Returns:
        A new stream after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$,​G,​H,​I> Stream<I> bind​(Stream<B> sb,
                                                                                                 Stream<C> sc,
                                                                                                 Stream<D> sd,
                                                                                                 Stream<E> se,
                                                                                                 Stream<F$> sf,
                                                                                                 Stream<G> sg,
                                                                                                 Stream<H> sh,
                                                                                                 F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​F<H,​I>>>>>>>> f)
        Binds the given function across each element of this stream and the given streams with a final join.
        Parameters:
        sb - A given stream to bind the given function with.
        sc - A given stream to bind the given function with.
        sd - A given stream to bind the given function with.
        se - A given stream to bind the given function with.
        sf - A given stream to bind the given function with.
        sg - A given stream to bind the given function with.
        sh - A given stream to bind the given function with.
        f - The function to apply to each element of this stream and the given streams.
        Returns:
        A new stream after performing the map, then final join.
      • sequence

        public final <B> Stream<B> sequence​(Stream<B> bs)
        Performs a bind across each stream element, but ignores the element value each time.
        Parameters:
        bs - The stream to apply in the final join.
        Returns:
        A new stream after the final join.
      • sequence

        public static <A> Stream<IO<A>> sequence​(IO<Stream<A>> io)
        Sequence through the Stream monad.
        Parameters:
        io - The IO stream to sequence.
        Returns:
        The stream of IOs after sequencing.
      • sequence

        public static <A> Stream<P1<A>> sequence​(F0<Stream<A>> p)
        Sequence through the Stream monad.
        Parameters:
        p - The lazy stream to sequence.
        Returns:
        The stream of (pre-calculated) lazy values after sequencing.
      • sequence

        public static <A> Stream<Option<A>> sequence​(Option<Stream<A>> o)
        Sequence through the Stream monad.
        Parameters:
        o - The optional stream to sequence.
        Returns:
        The stream of options after sequencing.
      • apply

        public final <B> Stream<B> apply​(Stream<F<A,​B>> sf)
        Performs function application within a stream (applicative functor pattern).
        Parameters:
        sf - The stream of functions to apply.
        Returns:
        A new stream after applying the given stream of functions through this stream.
      • interleave

        public final Stream<A> interleave​(Stream<A> as)
        Interleaves the given stream with this stream to produce a new stream.
        Parameters:
        as - The stream to interleave this stream with.
        Returns:
        A new stream with elements interleaved from this stream and the given stream.
      • enumerationStream

        public static <A> Stream<A> enumerationStream​(java.util.Enumeration<A> e)
      • sort

        public final Stream<A> sort​(Ord<A> o)
        Sort this stream according to the given ordering.
        Parameters:
        o - An ordering for the elements of this stream.
        Returns:
        A new stream with the elements of this stream sorted according to the given ordering.
      • sort

        public final Stream<A> sort​(Ord<A> o,
                                    Strategy<Unit> s)
        Sort this stream according to the given ordering, using a parallel Quick Sort algorithm that uses the given parallelisation strategy.
        Parameters:
        o - An ordering for the elements of this stream.
        s - A strategy for parallelising the algorithm.
        Returns:
        A new stream with the elements of this stream sorted according to the given ordering.
      • toCollection

        public final java.util.Collection<A> toCollection()
        Projects an immutable collection of this stream.
        Returns:
        An immutable collection of this stream.
      • range

        public static Stream<java.lang.Integer> range​(int from,
                                                      long to)
        Returns a stream of integers from the given from value (inclusive) to the given to value (exclusive).
        Parameters:
        from - The minimum value for the stream (inclusive).
        to - The maximum value for the stream (exclusive).
        Returns:
        A stream of integers from the given from value (inclusive) to the given to value (exclusive).
      • stream

        @SafeVarargs
        public static <A> Stream<A> stream​(A... as)
        Constructs a stream with the given elements.
        Parameters:
        as - The elements which which to construct a stream.
        Returns:
        a new stream with the given elements.
      • iteratorStream

        public static <A> Stream<A> iteratorStream​(java.util.Iterator<A> it)
        Constructs a stream with the given elements in the Iterator.
      • forever

        public static <A> Stream<A> forever​(Enumerator<A> e,
                                            A from)
        Returns a stream that is either infinite or bounded up to the maximum value of the given iterator starting at the given value and stepping at increments of 1.
        Parameters:
        e - The enumerator to compute successors from.
        from - The value to begin computing successors from.
        Returns:
        A stream that is either infinite or bounded up to the maximum value of the given iterator starting at the given value and stepping at increments of 1.
      • forever

        public static <A> Stream<A> forever​(Enumerator<A> e,
                                            A from,
                                            long step)
        Returns a stream that is either infinite or bounded up to the maximum value of the given iterator starting at the given value and stepping at the given increment.
        Parameters:
        e - The enumerator to compute successors from.
        from - The value to begin computing successors from.
        step - The increment to step.
        Returns:
        A stream that is either infinite or bounded up to the maximum value of the given iterator starting at the given value and stepping at the given increment.
      • range

        public static <A> Stream<A> range​(Enumerator<A> e,
                                          A from,
                                          A to)
        Returns a stream using the given enumerator from the given value to the other given value stepping at increments of 1.
        Parameters:
        e - The enumerator to compute successors from.
        from - The value to begin computing successors from.
        to - The value to stop computing successors from.
        Returns:
        A stream using the given enumerator from the given value to the other given value stepping at increments of 1.
      • range

        public static <A> Stream<A> range​(Enumerator<A> e,
                                          A from,
                                          A to,
                                          long step)
        Returns a stream using the given enumerator from the given value to the other given value stepping at the given increment.
        Parameters:
        e - The enumerator to compute successors from.
        from - The value to begin computing successors from.
        to - The value to stop computing successors from.
        step - The increment to step.
        Returns:
        A stream using the given enumerator from the given value to the other given value stepping at the given increment.
      • range

        public static Stream<java.lang.Integer> range​(int from)
        Returns an infinite stream of integers from the given from value (inclusive).
        Parameters:
        from - The minimum value for the stream (inclusive).
        Returns:
        A stream of integers from the given from value (inclusive).
      • filter

        public static <A> F<F<A,​java.lang.Boolean>,​F<Stream<A>,​Stream<A>>> filter()
        Returns a first-class version of the filter function.
        Returns:
        a function that filters a given stream using a given predicate.
      • zapp

        public final <B> Stream<B> zapp​(Stream<F<A,​B>> fs)
        Zips this stream with the given stream of functions, applying each function in turn to the corresponding element in this stream to produce a new stream. If this stream and the given stream have different lengths, then the longer stream is normalised so this function never fails.
        Parameters:
        fs - The stream of functions to apply to this stream.
        Returns:
        A new stream with a length the same as the shortest of this stream and the given stream.
      • zipWith

        public final <B,​C> Stream<C> zipWith​(Stream<B> bs,
                                                   F<A,​F<B,​C>> f)
        Zips this stream with the given stream using the given function to produce a new stream. If this stream and the given stream have different lengths, then the longer stream is normalised so this function never fails.
        Parameters:
        bs - The stream to zip this stream with.
        f - The function to zip this stream and the given stream with.
        Returns:
        A new stream with a length the same as the shortest of this stream and the given stream.
      • zipWith

        public final <B,​C> Stream<C> zipWith​(Stream<B> bs,
                                                   F2<A,​B,​C> f)
        Zips this stream with the given stream using the given function to produce a new stream. If this stream and the given stream have different lengths, then the longer stream is normalised so this function never fails.
        Parameters:
        bs - The stream to zip this stream with.
        f - The function to zip this stream and the given stream with.
        Returns:
        A new stream with a length the same as the shortest of this stream and the given stream.
      • zipWith

        public final <B,​C> F<Stream<B>,​Stream<C>> zipWith​(F<A,​F<B,​C>> f)
        Partially-applied version of zipWith. Returns a function that zips a given stream with this stream using the given function.
        Parameters:
        f - The function to zip this stream and a given stream with.
        Returns:
        A function that zips a given stream with this stream using the given function.
      • zip

        public final <B> Stream<P2<A,​B>> zip​(Stream<B> bs)
        Zips this stream with the given stream to produce a stream of pairs. If this stream and the given stream have different lengths, then the longer stream is normalised so this function never fails.
        Parameters:
        bs - The stream to zip this stream with.
        Returns:
        A new stream with a length the same as the shortest of this stream and the given stream.
      • zipIndex

        public final Stream<P2<A,​java.lang.Integer>> zipIndex()
        Zips this stream with the index of its element as a pair.
        Returns:
        A new stream with the same length as this stream.
      • toEither

        public final <X> Either<X,​A> toEither​(F0<X> x)
        Returns an either projection of this stream; the given argument in Left if empty, or the first element in Right.
        Parameters:
        x - The value to return in left if this stream is empty.
        Returns:
        An either projection of this stream.
      • toOption

        public final Option<A> toOption()
        Returns an option projection of this stream; None if empty, or the first element in Some.
        Returns:
        An option projection of this stream.
      • toList

        public final List<A> toList()
        Returns a list projection of this stream.
        Returns:
        A list projection of this stream.
      • toJavaList

        public final java.util.List<A> toJavaList()
        Returns a java.util.List projection of this stream.
      • toArray

        public final Array<A> toArray()
        Returns a array projection of this stream.
        Returns:
        A array projection of this stream.
      • toArray

        public final Array<A> toArray​(java.lang.Class<A[]> c)
        Returns a array projection of this stream.
        Parameters:
        c - The class type of the array to return.
        Returns:
        A array projection of this stream.
      • array

        public final A[] array​(java.lang.Class<A[]> c)
        Returns an array from this stream.
        Parameters:
        c - The class type of the array to return.
        Returns:
        An array from this stream.
      • cons

        public final Stream<A> cons​(A a)
        Prepends (cons) the given element to this stream to product a new stream.
        Parameters:
        a - The element to prepend.
        Returns:
        A new stream with the given element at the head.
      • asString

        public static java.lang.String asString​(Stream<java.lang.Character> cs)
        Returns a string from the given stream of characters. The inverse of this function is fromString(String).
        Parameters:
        cs - The stream of characters to produce the string from.
        Returns:
        A string from the given stream of characters.
      • fromString

        public static Stream<java.lang.Character> fromString​(java.lang.String s)
        Returns a stream of characters from the given string. The inverse of this function is asString(Stream).
        Parameters:
        s - The string to produce the stream of characters from.
        Returns:
        A stream of characters from the given string.
      • snoc

        public final Stream<A> snoc​(A a)
        Append the given element to this stream to product a new stream.
        Parameters:
        a - The element to append.
        Returns:
        A new stream with the given element at the end.
      • snoc

        public final Stream<A> snoc​(F0<A> a)
        Append the given element to this stream to produce a new stream.
        Parameters:
        a - The element to append.
        Returns:
        A new stream with the given element at the end.
      • take

        public final Stream<A> take​(int n)
        Returns the first n elements from the head of this stream.
        Parameters:
        n - The number of elements to take from this stream.
        Returns:
        The first n elements from the head of this stream.
      • drop

        public final Stream<A> drop​(int i)
        Drops the given number of elements from the head of this stream if they are available.
        Parameters:
        i - The number of elements to drop from the head of this stream.
        Returns:
        A stream with a length the same, or less than, this stream.
      • takeWhile

        public final Stream<A> takeWhile​(F<A,​java.lang.Boolean> f)
        Returns the first elements of the head of this stream that match the given predicate function.
        Parameters:
        f - The predicate function to apply on this stream until it finds an element that does not hold, or the stream is exhausted.
        Returns:
        The first elements of the head of this stream that match the given predicate function.
      • dropWhile

        public final Stream<A> dropWhile​(F<A,​java.lang.Boolean> f)
        Removes elements from the head of this stream that do not match the given predicate function until an element is found that does match or the stream is exhausted.
        Parameters:
        f - The predicate function to apply through this stream.
        Returns:
        The stream whose first element does not match the given predicate function.
      • span

        public final P2<Stream<A>,​Stream<A>> span​(F<A,​java.lang.Boolean> p)
        Returns a tuple where the first element is the longest prefix of this stream that satisfies the given predicate and the second element is the remainder of the stream.
        Parameters:
        p - A predicate to be satisfied by a prefix of this stream.
        Returns:
        A tuple where the first element is the longest prefix of this stream that satisfies the given predicate and the second element is the remainder of the stream.
      • replace

        public final Stream<A> replace​(F<A,​java.lang.Boolean> p,
                                       A a)
        Returns a new stream resulting from replacing all elements that match the given predicate with the given element.
        Parameters:
        p - The predicate to match replaced elements.
        a - The element with which to replace elements.
        Returns:
        A new stream resulting from replacing all elements that match the given predicate with the given element.
      • split

        public final P2<Stream<A>,​Stream<A>> split​(F<A,​java.lang.Boolean> p)
        Returns a tuple where the first element is the longest prefix of this stream that does not satisfy the given predicate and the second element is the remainder of the stream.
        Parameters:
        p - A predicate not to be satisfied by a prefix of this stream.
        Returns:
        A tuple where the first element is the longest prefix of this stream that does not satisfy the given predicate and the second element is the remainder of the stream.
      • reverse

        public final Stream<A> reverse()
        Reverse this stream in constant stack space.
        Returns:
        A new stream that is the reverse of this one.
      • last

        public final A last()
        Get the last element of this stream. Undefined for infinite streams.
        Returns:
        The last element in this stream, if there is one.
      • length

        public final int length()
        The length of this stream. This function will not terminate for an infinite stream.
        Returns:
        The length of this stream.
      • index

        public final A index​(int i)
        Returns the element at the given index if it exists, fails otherwise.
        Parameters:
        i - The index at which to get the element to return.
        Returns:
        The element at the given index if it exists, fails otherwise.
      • forall

        public final boolean forall​(F<A,​java.lang.Boolean> f)
        Returns true if the predicate holds for all of the elements of this stream, false otherwise (true for the empty stream).
        Parameters:
        f - the predicate function to test on each element of this stream.
        Returns:
        true if the predicate holds for all of the elements of this stream, false otherwise.
      • equals

        public final boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringLazy

        public final java.lang.String toStringLazy()
      • toStringEager

        public final java.lang.String toStringEager()
      • exists

        public final boolean exists​(F<A,​java.lang.Boolean> f)
        Returns true if the predicate holds for at least one of the elements of this stream, false otherwise (false for the empty stream).
        Parameters:
        f - The predicate function to test on the elements of this stream.
        Returns:
        true if the predicate holds for at least one of the elements of this stream.
      • find

        public final Option<A> find​(F<A,​java.lang.Boolean> f)
        Finds the first occurrence of an element that matches the given predicate or no value if no elements match.
        Parameters:
        f - The predicate function to test on elements of this stream.
        Returns:
        The first occurrence of an element that matches the given predicate or no value if no elements match.
      • cobind

        public final <B> Stream<B> cobind​(F<Stream<A>,​B> k)
        Binds the given function across the stream of substreams of this stream.
        Parameters:
        k - A function to bind across this stream and its substreams.
        Returns:
        a new stream of the results of applying the given function to this stream and its substreams.
      • tails

        public final Stream<Stream<A>> tails()
        Returns a stream of the suffixes of this stream. A stream is considered to be a suffix of itself in this context.
        Returns:
        a stream of the suffixes of this stream, starting with the stream itself.
      • inits

        public final Stream<Stream<A>> inits()
        Returns a stream of all prefixes of this stream. A stream is considered a prefix of itself in tnis context.
        Returns:
        a stream of the prefixes of this stream, starting with the stream itself.
      • substreams

        public final Stream<Stream<A>> substreams()
        Returns a stream of all infixes of this stream. A stream is considered to contain itself.
        Returns:
        a stream of the infixes of this stream.
      • indexOf

        public final Option<java.lang.Integer> indexOf​(F<A,​java.lang.Boolean> p)
        Returns the position of the first element matching the given predicate, if any.
        Parameters:
        p - A predicate to match.
        Returns:
        the position of the first element matching the given predicate, if any.
      • sequenceW

        public final <B> Stream<B> sequenceW​(Stream<F<Stream<A>,​B>> fs)
        Applies a stream of comonadic functions to this stream, returning a stream of values.
        Parameters:
        fs - A stream of comonadic functions to apply to this stream.
        Returns:
        A new stream of the results of applying the stream of functions to this stream.
      • toFunction

        public final F<java.lang.Integer,​A> toFunction()
        Converts this stream to a function of natural numbers.
        Returns:
        A function from natural numbers to values with the corresponding position in this stream.
      • fromFunction

        public static <A> Stream<A> fromFunction​(F<Natural,​A> f)
        Converts a function of natural numbers to a stream.
        Parameters:
        f - The function to convert to a stream.
        Returns:
        A new stream of the results of the given function applied to the natural numbers, starting at 0.
      • fromFunction

        public static <A,​B> Stream<A> fromFunction​(Enumerator<B> e,
                                                         F<B,​A> f,
                                                         B i)
        Converts a function of an enumerable type to a stream of the results of that function, starting at the given index.
        Parameters:
        e - An enumerator for the domain of the function.
        f - The function to convert to a stream.
        i - The index into the function at which to begin the stream.
        Returns:
        A new stream of the results of the given function applied to the values of the given enumerator, starting at the given value.
      • unzip

        public static <A,​B> P2<Stream<A>,​Stream<B>> unzip​(Stream<P2<A,​B>> xs)
        Transforms a stream of pairs into a stream of first components and a stream of second components.
        Parameters:
        xs - The stream of pairs to transform.
        Returns:
        A stream of first components and a stream of second components.
      • zipWith

        public static <A,​B,​C> F<Stream<A>,​F<Stream<B>,​F<F<A,​F<B,​C>>,​Stream<C>>>> zipWith()
        A first-class version of the zipWith function.
        Returns:
        a function that zips two given streams with a given function.
      • cons

        public static <A> F<A,​F<P1<Stream<A>>,​Stream<A>>> cons()
        Returns a function that prepends (cons) an element to a stream to produce a new stream.
        Returns:
        A function that prepends (cons) an element to a stream to produce a new stream.
      • cons_

        public static <A> F<A,​F<Stream<A>,​Stream<A>>> cons_()
        Returns a function that prepends (cons) an element to a stream to produce a new stream.
        Returns:
        A function that prepends (cons) an element to a stream to produce a new stream.
      • nil

        public static <A> Stream<A> nil()
        Returns an empty stream.
        Returns:
        An empty stream.
      • nil_

        public static <A> P1<Stream<A>> nil_()
        Returns an empty stream.
        Returns:
        An empty stream.
      • isEmpty_

        public static <A> F<Stream<A>,​java.lang.Boolean> isEmpty_()
        Returns a function that determines whether a given stream is empty.
        Returns:
        A function that determines whether a given stream is empty.
      • isNotEmpty_

        public static <A> F<Stream<A>,​java.lang.Boolean> isNotEmpty_()
        Returns a function that determines whether a given stream is not empty.
        Returns:
        A function that determines whether a given stream is not empty.
      • single

        public static <A> Stream<A> single​(A a)
        Returns a stream of one element containing the given value.
        Parameters:
        a - The value for the head of the returned stream.
        Returns:
        A stream of one element containing the given value.
      • single

        public static <A> F<A,​Stream<A>> single()
        Returns a function that yields a stream containing its argument.
        Returns:
        a function that yields a stream containing its argument.
      • cons

        public static <A> Stream<A> cons​(A head,
                                         F0<Stream<A>> tail)
        Prepends the given head element to the given tail element to produce a new stream.
        Parameters:
        head - The element to prepend.
        tail - The stream to prepend to.
        Returns:
        The stream with the given element prepended.
      • join

        public static <A> Stream<A> join​(Stream<Stream<A>> o)
        Joins the given stream of streams by concatenation.
        Parameters:
        o - The stream of streams to join.
        Returns:
        A new stream that is the join of the given streams.
      • join

        public static <A> F<Stream<Stream<A>>,​Stream<A>> join()
        A first-class version of join
        Returns:
        A function that joins a stream of streams using a bind operation.
      • unfold

        public static <A,​B> Stream<A> unfold​(F<B,​Option<P2<A,​B>>> f,
                                                   B b)
        Unfolds across the given function starting at the given value to produce a stream.
        Parameters:
        f - The function to unfold across.
        b - The start value to begin the unfold.
        Returns:
        A new stream that is a result of unfolding until the function does not produce a value.
      • iterateWhile

        public static <A> Stream<A> iterateWhile​(F<A,​A> f,
                                                 F<A,​java.lang.Boolean> p,
                                                 A a)
        Creates a stream where the first item is calculated by applying the function on the third argument, the second item by applying the function on the previous result and so on.
        Parameters:
        f - The function to iterate with.
        p - The predicate which must be true for the next item in order to continue the iteration.
        a - The input to the first iteration.
        Returns:
        A stream where the first item is calculated by applying the function on the third argument, the second item by applying the function on the previous result and so on.
      • iterableStream

        public static <A> Stream<A> iterableStream​(java.lang.Iterable<A> i)
        Takes the given iterable to a stream.
        Parameters:
        i - The iterable to take to a stream.
        Returns:
        A stream from the given iterable.
      • arrayStream

        @SafeVarargs
        public static <A> Stream<A> arrayStream​(A... as)
      • repeat

        public static <A> Stream<A> repeat​(A a)
        Returns an infinite-length stream of the given element.
        Parameters:
        a - The element to repeat infinitely.
        Returns:
        An infinite-length stream of the given element.
      • cycle

        public static <A> Stream<A> cycle​(Stream<A> as)
        Returns an infinite-length stream of the given elements cycling. Fails on the empty stream.
        Parameters:
        as - The elements to cycle infinitely. This must not be empty.
        Returns:
        An infinite-length stream of the given elements cycling.
      • iterate

        public static <A> Stream<A> iterate​(F<A,​A> f,
                                            A a)
        Returns a stream constructed by applying the given iteration function starting at the given value.
        Parameters:
        f - The iteration function.
        a - The value to begin iterating from.
        Returns:
        A stream constructed by applying the given iteration function starting at the given value.
      • iterate

        public static <A> F<F<A,​A>,​F<A,​Stream<A>>> iterate()
        A first-class version of the iterate function.
        Returns:
        A function that returns a stream constructed by applying a given iteration function starting at a given value.
      • bind_

        public static <A,​B> F<F<A,​Stream<B>>,​F<Stream<A>,​Stream<B>>> bind_()
        A first-class version of the bind function.
        Returns:
        A function that binds a given function across a given stream, joining the resulting streams.
      • foldRight

        public static <A,​B> F<F<A,​F<P1<B>,​B>>,​F<B,​F<Stream<A>,​B>>> foldRight()
        A first-class version of the foldRight function.
        Returns:
        A function that folds a given stream with a given function.
      • sequenceEither

        public static <L,​B> Either<L,​Stream<B>> sequenceEither​(Stream<Either<L,​B>> stream)
        Sequence the given stream and collect the output on the right side of an either.
        Type Parameters:
        B - the type of the right value
        L - the type of the left value
        Parameters:
        stream - the given stream
        Returns:
        the either
      • sequenceEitherLeft

        public static <R,​B> Either<Stream<B>,​R> sequenceEitherLeft​(Stream<Either<B,​R>> stream)
        Sequence the given stream and collect the output on the left side of an either.
        Type Parameters:
        R - the type of the right value
        B - the type of the left value
        Parameters:
        stream - the given stream
        Returns:
        the either
      • sequenceEitherRight

        public static <L,​B> Either<L,​Stream<B>> sequenceEitherRight​(Stream<Either<L,​B>> stream)
        Sequence the given stream and collect the output on the right side of an either.
        Type Parameters:
        B - the type of the right value
        L - the type of the left value
        Parameters:
        stream - the given stream
        Returns:
        the either
      • sequenceF

        public static <C,​B> F<C,​Stream<B>> sequenceF​(Stream<F<C,​B>> stream)
        Sequence the given stream and collect the output as a function.
        Type Parameters:
        C - the type of the input value
        B - the type of the output value
        Parameters:
        stream - the given stream
        Returns:
        the either
      • sequenceIO

        public static <B> IO<Stream<B>> sequenceIO​(Stream<IO<B>> stream)
        Sequence the given stream and collect the output as an IO.
        Type Parameters:
        B - the type of the IO value
        Parameters:
        stream - the given stream
        Returns:
        the IO
      • sequenceList

        public static <B> List<Stream<B>> sequenceList​(Stream<List<B>> stream)
        Sequence the given stream and collect the output as a list.
        Type Parameters:
        B - the type of the list value
        Parameters:
        stream - the given stream
        Returns:
        the list
      • sequenceOption

        public static <B> Option<Stream<B>> sequenceOption​(Stream<Option<B>> stream)
        Sequence the given stream and collect the output as an stream.
        Type Parameters:
        B - the type of the option value
        Parameters:
        stream - the given stream
        Returns:
        the stream
      • sequenceP1

        public static <B> P1<Stream<B>> sequenceP1​(Stream<P1<B>> stream)
        Sequence the given stream and collect the output as a P1.
        Type Parameters:
        B - the type of the P1 value
        Parameters:
        stream - the given stream
        Returns:
        the P1
      • sequenceSeq

        public static <B> Seq<Stream<B>> sequenceSeq​(Stream<Seq<B>> stream)
        Sequence the given stream and collect the output as a seq.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        stream - the given stream
        Returns:
        the seq
      • sequenceSet

        public static <B> Set<Stream<B>> sequenceSet​(Ord<B> ord,
                                                     Stream<Set<B>> stream)
        Sequence the given stream and collect the output as a set; use the given ord to order the set.
        Type Parameters:
        B - the type of the set value
        Parameters:
        ord - the given ord
        stream - the given stream
        Returns:
        the either
      • sequenceStream

        public static <B> Stream<Stream<B>> sequenceStream​(Stream<Stream<B>> stream)
        Sequence the given stream and collect the output as a stream.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        stream - the given stream
        Returns:
        the stream
      • sequenceTrampoline

        public static <B> Trampoline<Stream<B>> sequenceTrampoline​(Stream<Trampoline<B>> stream)
        Sequence the given stream and collect the output as a trampoline.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        stream - the given trampoline
        Returns:
        the stream
      • sequenceValidation

        public static <E,​B> Validation<E,​Stream<B>> sequenceValidation​(Stream<Validation<E,​B>> stream)
        Sequence the given stream and collect the output as a validation.
        Type Parameters:
        E - the type of the failure value
        B - the type of the success value
        Parameters:
        stream - the given stream
        Returns:
        the validation
      • sequenceValidation

        public static <E,​B> Validation<E,​Stream<B>> sequenceValidation​(Semigroup<E> semigroup,
                                                                                   Stream<Validation<E,​B>> stream)
        Sequence the given stream and collect the output as a validation; use the given semigroup to reduce the errors.
        Type Parameters:
        E - the type of the failure value
        B - the type of the success value
        Parameters:
        semigroup - the given semigroup
        stream - the given stream
        Returns:
        the validation
      • traverseEither

        public <B,​L> Either<L,​Stream<B>> traverseEither​(F<A,​Either<L,​B>> f)
        Traverse this stream with the given function and collect the output on the right side of an either.
        Type Parameters:
        L - the type of the left value
        B - the type of the right value
        Parameters:
        f - the given function
        Returns:
        the either
      • traverseEitherLeft

        public <R,​B> Either<Stream<B>,​R> traverseEitherLeft​(F<A,​Either<B,​R>> f)
        Traverse this stream with the given function and collect the output on the left side of an either.
        Type Parameters:
        R - the type of the left value
        B - the type of the right value
        Parameters:
        f - the given function
        Returns:
        the either
      • traverseEitherRight

        public <L,​B> Either<L,​Stream<B>> traverseEitherRight​(F<A,​Either<L,​B>> f)
        Traverse this stream with the given function and collect the output on the right side of an either.
        Type Parameters:
        L - the type of the left value
        B - the type of the right value
        Parameters:
        f - the given function
        Returns:
        the either
      • traverseF

        public <C,​B> F<C,​Stream<B>> traverseF​(F<A,​F<C,​B>> f)
        Traverse this stream with the given function and collect the output as a function.
        Type Parameters:
        C - the type of the input value
        B - the type of the output value
        Parameters:
        f - the given function
        Returns:
        the function
      • traverseIO

        public <B> IO<Stream<B>> traverseIO​(F<A,​IO<B>> f)
        Traverse this stream with the given function and collect the output as an IO.
        Type Parameters:
        B - the type of the IO value
        Parameters:
        f - the given function
        Returns:
        the IO
      • traverseList

        public <B> List<Stream<B>> traverseList​(F<A,​List<B>> f)
        Traverse this stream with the given function and collect the output as a list.
        Type Parameters:
        B - the type of the list value
        Parameters:
        f - the given function
        Returns:
        the list
      • traverseOption

        public <B> Option<Stream<B>> traverseOption​(F<A,​Option<B>> f)
        Traverses through the Seq with the given function
        Parameters:
        f - The function that produces Option value
        Returns:
        none if applying f returns none to any element of the seq or f mapped seq in some .
      • traverseP1

        public <B> P1<Stream<B>> traverseP1​(F<A,​P1<B>> f)
        Traverse this stream with the given function and collect the output as a p1.
        Type Parameters:
        B - the type of the p1 value
        Parameters:
        f - the given function
        Returns:
        the p1
      • traverseSeq

        public <B> Seq<Stream<B>> traverseSeq​(F<A,​Seq<B>> f)
        Traverse this stream with the given function and collect the output as a seq.
        Type Parameters:
        B - the type of the seq value
        Parameters:
        f - the given function
        Returns:
        the seq
      • traverseSet

        public <B> Set<Stream<B>> traverseSet​(Ord<B> ord,
                                              F<A,​Set<B>> f)
        Traverse this stream with the given function and collect the output as a set; use the given ord to order the set.
        Type Parameters:
        B - the type of the set value
        Parameters:
        ord - the given ord
        f - the given function
        Returns:
        the set
      • traverseStream

        public <B> Stream<Stream<B>> traverseStream​(F<A,​Stream<B>> f)
        Traverse this stream with the given function and collect the output as a stream.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        f - the given function
        Returns:
        the stream
      • traverseTrampoline

        public <B> Trampoline<Stream<B>> traverseTrampoline​(F<A,​Trampoline<B>> f)
        Traverse this stream with the given function and collect the output as a trampoline.
        Type Parameters:
        B - the type of the trampoline value
        Parameters:
        f - the given function
        Returns:
        the trampoline
      • traverseValidation

        public final <E,​B> Validation<E,​Stream<B>> traverseValidation​(F<A,​Validation<E,​B>> f)
        Traverse this stream with the given function and collect the output as a validation.
        Type Parameters:
        E - the type of the failure value
        B - the type of the success value
        Parameters:
        f - the given function
        Returns:
        the validation
      • traverseValidation

        public final <E,​B> Validation<E,​Stream<B>> traverseValidation​(Semigroup<E> semigroup,
                                                                                  F<A,​Validation<E,​B>> f)
        Traverse this stream with the given function and collect the output as a validation; use the given semigroup to reduce the errors.
        Type Parameters:
        E - the type of the failure value
        B - the type of the success value
        Parameters:
        semigroup - the given semigroup
        f - the given function
        Returns:
        the validation