Package fj.data
Class Stream<A>
java.lang.Object
fj.data.Stream<A>
- All Implemented Interfaces:
Iterable<A>
- Direct Known Subclasses:
Stream.Cons
,Stream.Nil
A lazy (not yet evaluated), immutable, singly linked list.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the given stream to this stream.Appends the given stream to this stream.final <B> Stream
<B> Performs function application within a stream (applicative functor pattern).final A[]
Returns an array from this stream.static <A> Stream
<A> arrayStream
(A... as) static String
Returns a string from the given stream of characters.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.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.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.final <B,
C, D, E, F$>
Stream<F$> Binds the given function across each element of this stream and the given streams with a final join.final <B,
C, D, E>
Stream<E> Binds the given function across each element of this stream and the given streams with a final join.final <B,
C, D> Stream <D> Binds the given function across each element of this stream and the given streams with a final join.final <B,
C> Stream <C> Binds the given function across each element of this stream and the given stream with a final join.final <B,
C> Stream <C> Binds the given function across each element of this stream and the given stream with a final join.final <B> Stream
<B> Binds the given function across each element of this stream with a final join.bind_()
A first-class version of the bind function.final <B> Stream
<B> Binds the given function across the stream of substreams of this stream.cons()
Returns a function that prepends (cons) an element to a stream to produce a new stream.Prepends (cons) the given element to this stream to product a new stream.static <A> Stream
<A> Prepends the given head element to the given tail element to produce a new stream.cons_()
Returns a function that prepends (cons) an element to a stream to produce a new stream.static <A> Stream
<A> Returns an infinite-length stream of the given elements cycling.drop
(int i) Drops the given number of elements from the head of this stream if they are available.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
(Enumeration<A> e) final boolean
final boolean
Returnstrue
if the predicate holds for at least one of the elements of this stream,false
otherwise (false
for the empty stream).filter()
Returns a first-class version of the filter function.Filters elements from this stream by returning only elements which producetrue
when the given function is applied to them.Finds the first occurrence of an element that matches the given predicate or no value if no elements match.final <B> B
Performs a left-fold reduction across this stream.final <B> B
Performs a left-fold reduction across this stream.final A
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.final A
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 first-class version of the foldRight function.final <B> B
Performs a right-fold reduction across this stream.final <B> B
Performs a right-fold reduction across this stream.final <B> B
foldRight1
(F<A, F<B, B>> f, B b) Performs a right-fold reduction across this stream.final <B> B
foldRight1
(F2<A, B, B> f, B b) Performs a right-fold reduction across this stream.final boolean
Returnstrue
if the predicate holds for all of the elements of this stream,false
otherwise (true
for the empty stream).final Unit
Performs a side-effect for each element of this stream.final 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 of1
.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.fromString
(String s) Returns a stream of characters from the given string.final int
hashCode()
abstract A
head()
The first element of the stream or fails for the empty stream.final A
index
(int i) Returns the element at the given index if it exists, fails otherwise.Returns the position of the first element matching the given predicate, if any.inits()
Returns a stream of all prefixes of this stream.interleave
(Stream<A> as) Interleaves the given stream with this stream to produce a new stream.intersperse
(A a) Intersperses the given value between each two elements of the stream.final boolean
isEmpty()
Returnstrue
if this stream is empty,false
otherwise.isEmpty_()
Returns a function that determines whether a given stream is empty.final boolean
Returnsfalse
if this stream is empty,true
otherwise.Returns a function that determines whether a given stream is not empty.static <A> Stream
<A> iterableStream
(Iterable<A> i) Takes the given iterable to a stream.iterate()
A first-class version of the iterate function.static <A> Stream
<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, 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.iterator()
Returns an iterator for this stream.static <A> Stream
<A> iteratorStream
(Iterator<A> it) Constructs a stream with the given elements in the Iterator.join()
A first-class version of joinstatic <A> Stream
<A> Joins the given stream of streams by concatenation.final A
last()
Get the last element of this stream.final int
length()
The length of this stream.final <B> Stream
<B> Maps the given function across this stream.map_()
Provides a first-class version of the map function.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> mergePairs
(Ord<A> o, Stream<Stream<A>> s) private static <A> Stream
<A> 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.nil_()
Returns an empty stream.final A
Returns the head of this stream if there is one or the given argument if this stream is empty.Returns the tail of this stream if there is one or the given argument if this stream is empty.range
(int from) Returns an infinite stream of integers from the givenfrom
value (inclusive).range
(int from, long to) Returns a stream of integers from the givenfrom
value (inclusive) to the givento
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 of1
.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.Filters elements from this stream by returning only elements which producefalse
when the given function is applied to them.static <A> Stream
<A> repeat
(A a) Returns an infinite-length stream of the given element.Returns a new stream resulting from replacing all elements that match the given predicate with the given element.reverse()
Reverse this stream in constant stack space.Sequence through the Stream monad.Sequence through the Stream monad.final <B> Stream
<B> Performs a bind across each stream element, but ignores the element value each time.Sequence through the Stream monad.Turn a stream of functions into a function returning a stream.sequenceEither
(Stream<Either<L, B>> stream) Sequence the given stream and collect the output on the right side of an either.sequenceEitherLeft
(Stream<Either<B, R>> stream) Sequence the given stream and collect the output on the left side of an either.sequenceEitherRight
(Stream<Either<L, B>> stream) Sequence the given stream and collect the output on the right side of an either.Sequence the given stream and collect the output as a function.sequenceIO
(Stream<IO<B>> stream) Sequence the given stream and collect the output as an IO.sequenceList
(Stream<List<B>> stream) Sequence the given stream and collect the output as a list.sequenceOption
(Stream<Option<B>> stream) Sequence the given stream and collect the output as an stream.sequenceP1
(Stream<P1<B>> stream) Sequence the given stream and collect the output as a P1.sequenceSeq
(Stream<Seq<B>> stream) Sequence the given stream and collect the output as a seq.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.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.final <B> Stream
<B> Applies a stream of comonadic functions to this stream, returning a stream of values.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.Append the given element to this stream to product a new stream.Append the given element to this stream to produce a new stream.Sort this stream according to the given ordering.Sort this stream according to the given ordering, using a parallel Quick Sort algorithm that uses the given parallelisation strategy.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.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.Returns a stream of all infixes of this stream.tail()
The stream without the first element or fails for the empty stream.tails()
Returns a stream of the suffixes of this stream.take
(int n) Returns the firstn
elements from the head of this stream.Returns the first elements of the head of this stream that match the given predicate function.toArray()
Returns a array projection of this stream.Returns a array projection of this stream.final Collection
<A> Projects an immutable collection of this stream.Returns an either projection of this stream; the given argument inLeft
if empty, or the first element inRight
.Converts this stream to a function of natural numbers.Returns a java.util.List projection of this stream.toList()
Returns a list projection of this stream.toOption()
Returns an option projection of this stream;None
if empty, or the first element inSome
.final String
toString()
final String
final String
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.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.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.Traverse this stream with the given function and collect the output as a function.traverseIO
(F<A, IO<B>> f) Traverse this stream with the given function and collect the output as an IO.traverseList
(F<A, List<B>> f) Traverse this stream with the given function and collect the output as a list.traverseOption
(F<A, Option<B>> f) Traverses through the Seq with the given functiontraverseP1
(F<A, P1<B>> f) Traverse this stream with the given function and collect the output as a p1.traverseSeq
(F<A, Seq<B>> f) Traverse this stream with the given function and collect the output as a seq.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.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.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.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.final <B> B
Performs a reduction on this stream using the given arguments.static <A,
B> Stream <A> Unfolds across the given function starting at the given value to produce a stream.Transforms a stream of pairs into a stream of first components and a stream of second components.final <B> Stream
<B> 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.Zips this stream with the given stream to produce a stream of pairs.zipIndex()
Zips this stream with the index of its element as a pair.zipWith()
A first-class version of the zipWith function.final <B,
C> Stream <C> Zips this stream with the given stream using the given function to produce a new stream.final <B,
C> Stream <C> Zips this stream with the given stream using the given function to produce a new stream.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 Details
-
Stream
private Stream()
-
-
Method Details
-
iterator
Returns an iterator for this stream. This method exists to permit the use in afor
-each loop. -
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
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()Returnstrue
if this stream is empty,false
otherwise.- Returns:
true
if this stream is empty,false
otherwise.
-
isNotEmpty
public final boolean isNotEmpty()Returnsfalse
if this stream is empty,true
otherwise.- Returns:
false
if this stream is empty,true
otherwise.
-
uncons
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
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
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
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
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
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
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
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
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
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
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
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
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_
Provides a first-class version of the map function.- Returns:
- A function that maps a given function across a given stream.
-
foreach
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
Performs a side-effect for each element of this stream.- Parameters:
f
- The side-effect to perform for the given element.
-
filter
Filters elements from this stream by returning only elements which producetrue
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
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
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
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
Filters elements from this stream by returning only elements which producefalse
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_
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
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
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
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
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
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, Stream<E> bindD, E> (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, Stream<F$> bindD, E, F$> (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, Stream<G> bindD, E, F$, G> (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, Stream<H> bindD, E, F$, G, H> (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, Stream<I> bindD, E, F$, G, H, I> (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
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
Sequence through the Stream monad.- Parameters:
io
- The IO stream to sequence.- Returns:
- The stream of IOs after sequencing.
-
sequence
Sequence through the Stream monad.- Parameters:
p
- The lazy stream to sequence.- Returns:
- The stream of (pre-calculated) lazy values after sequencing.
-
sequence
Sequence through the Stream monad.- Parameters:
o
- The optional stream to sequence.- Returns:
- The stream of options after sequencing.
-
apply
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
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
-
sort
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.
-
mergesort
-
mergePairs
-
merge
-
sort
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.
-
qs
-
qs_
-
flt
-
toCollection
Projects an immutable collection of this stream.- Returns:
- An immutable collection of this stream.
-
range
Returns a stream of integers from the givenfrom
value (inclusive) to the givento
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 givento
value (exclusive).
-
stream
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
Constructs a stream with the given elements in the Iterator. -
forever
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 of1
.- 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
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
Returns a stream using the given enumerator from the given value to the other given value stepping at increments of1
.- 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
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
Returns an infinite stream of integers from the givenfrom
value (inclusive).- Parameters:
from
- The minimum value for the stream (inclusive).- Returns:
- A stream of integers from the given
from
value (inclusive).
-
filter
Returns a first-class version of the filter function.- Returns:
- a function that filters a given stream using a given predicate.
-
zapp
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
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
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
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
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
Zips this stream with the index of its element as a pair.- Returns:
- A new stream with the same length as this stream.
-
toEither
Returns an either projection of this stream; the given argument inLeft
if empty, or the first element inRight
.- Parameters:
x
- The value to return in left if this stream is empty.- Returns:
- An either projection of this stream.
-
toOption
Returns an option projection of this stream;None
if empty, or the first element inSome
.- Returns:
- An option projection of this stream.
-
toList
Returns a list projection of this stream.- Returns:
- A list projection of this stream.
-
toJavaList
Returns a java.util.List projection of this stream. -
toArray
Returns a array projection of this stream.- Returns:
- A array projection of this stream.
-
toArray
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
Returns an array from this stream.- Parameters:
c
- The class type of the array to return.- Returns:
- An array from this stream.
-
cons
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
Returns a string from the given stream of characters. The inverse of this function isfromString(String)
.- Parameters:
cs
- The stream of characters to produce the string from.- Returns:
- A string from the given stream of characters.
-
fromString
Returns a stream of characters from the given string. The inverse of this function isasString(Stream)
.- Parameters:
s
- The string to produce the stream of characters from.- Returns:
- A stream of characters from the given string.
-
snoc
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
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
Returns the firstn
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
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
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
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
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
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
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
Reverse this stream in constant stack space.- Returns:
- A new stream that is the reverse of this one.
-
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
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
Returnstrue
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
-
hashCode
public final int hashCode() -
toString
-
toStringLazy
-
toStringEager
-
exists
Returnstrue
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
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
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
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
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
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
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
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
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
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
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
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
A first-class version of the zipWith function.- Returns:
- a function that zips two given streams with a given function.
-
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_
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
Returns an empty stream.- Returns:
- An empty stream.
-
nil_
Returns an empty stream.- Returns:
- An empty stream.
-
isEmpty_
Returns a function that determines whether a given stream is empty.- Returns:
- A function that determines whether a given stream is empty.
-
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
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
Returns a function that yields a stream containing its argument.- Returns:
- a function that yields a stream containing its argument.
-
cons
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
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
A first-class version of join- Returns:
- A function that joins a stream of streams using a bind operation.
-
unfold
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
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
Takes the given iterable to a stream.- Parameters:
i
- The iterable to take to a stream.- Returns:
- A stream from the given iterable.
-
arrayStream
-
repeat
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
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
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
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_
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
A first-class version of the foldRight function.- Returns:
- A function that folds a given stream with a given function.
-
sequenceEither
Sequence the given stream and collect the output on the right side of an either.- Type Parameters:
L
- the type of the left valueB
- the type of the right value- Parameters:
stream
- the given stream- Returns:
- the either
-
sequenceEitherLeft
Sequence the given stream and collect the output on the left side of an either.- Type Parameters:
R
- the type of the right valueB
- the type of the left value- Parameters:
stream
- the given stream- Returns:
- the either
-
sequenceEitherRight
Sequence the given stream and collect the output on the right side of an either.- Type Parameters:
L
- the type of the left valueB
- the type of the right value- Parameters:
stream
- the given stream- Returns:
- the either
-
sequenceF
Sequence the given stream and collect the output as a function.- Type Parameters:
C
- the type of the input valueB
- the type of the output value- Parameters:
stream
- the given stream- Returns:
- the either
-
sequenceIO
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
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
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
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
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
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 ordstream
- the given stream- Returns:
- the either
-
sequenceStream
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
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
Sequence the given stream and collect the output as a validation.- Type Parameters:
E
- the type of the failure valueB
- 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 valueB
- the type of the success value- Parameters:
semigroup
- the given semigroupstream
- the given stream- Returns:
- the validation
-
traverseEither
Traverse this stream with the given function and collect the output on the right side of an either.- Type Parameters:
B
- the type of the right valueL
- the type of the left value- Parameters:
f
- the given function- Returns:
- the either
-
traverseEitherLeft
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 valueB
- the type of the right value- Parameters:
f
- the given function- Returns:
- the either
-
traverseEitherRight
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 valueB
- the type of the right value- Parameters:
f
- the given function- Returns:
- the either
-
traverseF
Traverse this stream with the given function and collect the output as a function.- Type Parameters:
C
- the type of the input valueB
- the type of the output value- Parameters:
f
- the given function- Returns:
- the function
-
traverseIO
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
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
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
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
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
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 ordf
- the given function- Returns:
- the set
-
traverseStream
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
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
Traverse this stream with the given function and collect the output as a validation.- Type Parameters:
E
- the type of the failure valueB
- 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 valueB
- the type of the success value- Parameters:
semigroup
- the given semigroupf
- the given function- Returns:
- the validation
-