Interface ImmutableFiniteIterable<A>
-
- Type Parameters:
A
- the element type
- All Superinterfaces:
EnhancedIterable<A>
,FiniteIterable<A>
,com.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
,ImmutableIterable<A>
,java.lang.Iterable<A>
- All Known Subinterfaces:
ImmutableNonEmptyFiniteIterable<A>
public interface ImmutableFiniteIterable<A> extends ImmutableIterable<A>, FiniteIterable<A>
AnEnhancedIterable
that is both finite and safe from mutation.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default ImmutableNonEmptyFiniteIterable<A>
append(A element)
Lazily appends an element to the end of thisImmutableFiniteIterable
, yielding a newImmutableNonEmptyFiniteIterable
.default ImmutableFiniteIterable<A>
concat(ImmutableFiniteIterable<A> other)
Lazily concatenates anotherImmutableFiniteIterable
to the end of thisImmutableFiniteIterable
, yielding a newImmutableFiniteIterable
.default ImmutableNonEmptyFiniteIterable<A>
concat(ImmutableNonEmptyFiniteIterable<A> other)
Lazily concatenates anImmutableNonEmptyFiniteIterable
to the end of thisImmutableFiniteIterable
, yielding a newImmutableNonEmptyFiniteIterable
.static <A> ImmutableFiniteIterable<A>
copyFrom(int maxCount, java.lang.Iterable<A> source)
Creates anImmutableFiniteIterable
by copying elements from anIterable
.static <A> ImmutableFiniteIterable<A>
copyFrom(java.util.Collection<A> source)
Creates anImmutableFiniteIterable
by copying elements from aCollection
.static <A> ImmutableFiniteIterable<A>
copyFrom(FiniteIterable<A> source)
Creates anImmutableFiniteIterable
by copying elements from aFiniteIterable
.default <B> ImmutableFiniteIterable<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>>
cross(ImmutableFiniteIterable<B> other)
Returns the lazily computed cartesian product of thisImmutableFiniteIterable
with anotherImmutableFiniteIterable
.default ImmutableIterable<A>
cycle()
Returns an infiniteImmutableIterable
that repeatedly cycles thisImmutableFiniteIterable
's elements, in order.default ImmutableFiniteIterable<A>
distinct()
Returns aImmutableFiniteIterable
of the distinct values from thisImmutableFiniteIterable
.default ImmutableFiniteIterable<A>
drop(int count)
Returns a newImmutableFiniteIterable
that drops the firstcount
elements of thisImmutableFiniteIterable
.default ImmutableFiniteIterable<A>
dropWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableFiniteIterable
that skips the first contiguous group of elements of thisImmutableFiniteIterable
that satisfy a predicate.static <A> ImmutableFiniteIterable<A>
emptyImmutableFiniteIterable()
Creates an emptyImmutableFiniteIterable
.default ImmutableFiniteIterable<A>
filter(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableFiniteIterable
that contains all elements of thisImmutableFiniteIterable
that satisfy a predicate.default <B> ImmutableFiniteIterable<B>
fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newImmutableFiniteIterable
by applying a function to all elements of thisImmutableFiniteIterable
.default ImmutableNonEmptyFiniteIterable<? extends ImmutableFiniteIterable<A>>
inits()
Returns anImmutableNonEmptyIterable
containing all of the subsequences of initial elements of thisImmutableFiniteIterable
, ordered by size, starting with the empty list.default ImmutableFiniteIterable<A>
intersperse(A separator)
Returns a newImmutableFiniteIterable
with the provided separator value injected between each value of thisImmutableFiniteIterable
.default ImmutableFiniteIterable<? extends ImmutableNonEmptyFiniteIterable<A>>
magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisImmutableFiniteIterable
that match a predicate pairwise.static <A> ImmutableNonEmptyFiniteIterable<A>
of(A first, A... more)
Creates anImmutableFiniteIterable
containing the given elements.default <B,C>
com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends ImmutableFiniteIterable<B>,? extends ImmutableFiniteIterable<C>>partition(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends com.jnape.palatable.lambda.adt.coproduct.CoProduct2<B,C,?>> function)
Partitions thisImmutableFiniteIterable
given a disjoint mapping function.default ImmutableNonEmptyFiniteIterable<A>
prepend(A element)
Lazily prepends an element to the front of thisImmutableFiniteIterable
, yielding a newImmutableNonEmptyFiniteIterable
.default ImmutableFiniteIterable<A>
prependAll(A separator)
Returns a newImmutableFiniteIterable
with the provided separator value injected before each value of thisImmutableFiniteIterable
.default ImmutableFiniteIterable<A>
reverse()
Returns a reversed representation of thisImmutableFiniteIterable
.default ImmutableFiniteIterable<? extends ImmutableNonEmptyFiniteIterable<A>>
slide(int k)
"Slides" a window ofk
elements across theImmutableFiniteIterable
by one element at a time.default com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends ImmutableFiniteIterable<A>,? extends ImmutableFiniteIterable<A>>
span(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns aTuple2
where the first slot is the front contiguous elements of thisImmutableFiniteIterable
matching a predicate and the second slot is all the remaining elements.default ImmutableNonEmptyIterable<? extends ImmutableFiniteIterable<A>>
tails()
Returns anImmutableNonEmptyIterable
containing all of the subsequences of tail elements of thisImmutableFiniteIterable
, ordered by size, starting with the full list.default ImmutableFiniteIterable<A>
takeWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableFiniteIterable
that limits to the first contiguous group of elements of thisFiniteIterable
that satisfy a predicate.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableFiniteIterable<A>>
toFinite()
Always succeeds becauseImmutableFiniteIterable
s are always finite.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyFiniteIterable<A>>
toNonEmpty()
Converts thisImmutableFiniteIterable
to aImmutableNonEmptyFiniteIterable
if it contains one or more elements.default <B,C>
ImmutableFiniteIterable<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableIterable<B> other)
Zips together thisImmutableFiniteIterable
with anotherImmutableIterable
by applying a zipping function.-
Methods inherited from interface software.kes.enhancediterables.EnhancedIterable
concat, concat, find, isEmpty, toArray, toCollection, zipWith, zipWith
-
Methods inherited from interface software.kes.enhancediterables.FiniteIterable
concat, concat, concat, cross, cross, foldLeft, foldRight, size, zipWith
-
Methods inherited from interface software.kes.enhancediterables.ImmutableIterable
concat, concat, take, zipWith
-
-
-
-
Method Detail
-
append
default ImmutableNonEmptyFiniteIterable<A> append(A element)
Lazily appends an element to the end of thisImmutableFiniteIterable
, yielding a newImmutableNonEmptyFiniteIterable
.- Specified by:
append
in interfaceEnhancedIterable<A>
- Specified by:
append
in interfaceFiniteIterable<A>
- Specified by:
append
in interfaceImmutableIterable<A>
- Parameters:
element
- the element to append- Returns:
- an
ImmutableNonEmptyFiniteIterable<A>
-
concat
default ImmutableFiniteIterable<A> concat(ImmutableFiniteIterable<A> other)
Lazily concatenates anotherImmutableFiniteIterable
to the end of thisImmutableFiniteIterable
, yielding a newImmutableFiniteIterable
.- Parameters:
other
- the otherImmutableFiniteIterable
- Returns:
- an
ImmutableFiniteIterable<A>
-
concat
default ImmutableNonEmptyFiniteIterable<A> concat(ImmutableNonEmptyFiniteIterable<A> other)
Lazily concatenates anImmutableNonEmptyFiniteIterable
to the end of thisImmutableFiniteIterable
, yielding a newImmutableNonEmptyFiniteIterable
.- Parameters:
other
- anImmutableNonEmptyFiniteIterable
- Returns:
- an
ImmutableNonEmptyFiniteIterable<A>
-
cross
default <B> ImmutableFiniteIterable<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>> cross(ImmutableFiniteIterable<B> other)
Returns the lazily computed cartesian product of thisImmutableFiniteIterable
with anotherImmutableFiniteIterable
.- Type Parameters:
B
- the type of the otherImmutableFiniteIterable
- Parameters:
other
- anImmutableFiniteIterable
of any type- Returns:
- a
ImmutableFiniteIterable<Tuple2<A, B>>
-
cycle
default ImmutableIterable<A> cycle()
Returns an infiniteImmutableIterable
that repeatedly cycles thisImmutableFiniteIterable
's elements, in order.- Specified by:
cycle
in interfaceFiniteIterable<A>
- Returns:
- an
ImmutableIterable<A>
-
distinct
default ImmutableFiniteIterable<A> distinct()
Returns aImmutableFiniteIterable
of the distinct values from thisImmutableFiniteIterable
.- Specified by:
distinct
in interfaceFiniteIterable<A>
- Returns:
- a
ImmutableFiniteIterable<A>
-
drop
default ImmutableFiniteIterable<A> drop(int count)
Returns a newImmutableFiniteIterable
that drops the firstcount
elements of thisImmutableFiniteIterable
.- Specified by:
drop
in interfaceEnhancedIterable<A>
- Specified by:
drop
in interfaceFiniteIterable<A>
- Specified by:
drop
in interfaceImmutableIterable<A>
- Parameters:
count
- the number of elements to drop from thisImmutableFiniteIterable
. Must be >= 0. May exceed size of thisImmutableFiniteIterable
, in which case, the result will be an emptyImmutableFiniteIterable
.- Returns:
- an
ImmutableFiniteIterable<A>
-
dropWhile
default ImmutableFiniteIterable<A> dropWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableFiniteIterable
that skips the first contiguous group of elements of thisImmutableFiniteIterable
that satisfy a predicate.Iteration begins at the first element for which the predicate evaluates to false.
- Specified by:
dropWhile
in interfaceEnhancedIterable<A>
- Specified by:
dropWhile
in interfaceFiniteIterable<A>
- Specified by:
dropWhile
in interfaceImmutableIterable<A>
- Parameters:
predicate
- a predicate; should be referentially transparent and not have side-effects- Returns:
- a
ImmutableFiniteIterable<A>
-
filter
default ImmutableFiniteIterable<A> filter(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableFiniteIterable
that contains all elements of thisImmutableFiniteIterable
that satisfy a predicate.- Specified by:
filter
in interfaceEnhancedIterable<A>
- Specified by:
filter
in interfaceFiniteIterable<A>
- Specified by:
filter
in interfaceImmutableIterable<A>
- Parameters:
predicate
- a predicate; should be referentially transparent and not have side-effects- Returns:
- a
ImmutableFiniteIterable<A>
-
fmap
default <B> ImmutableFiniteIterable<B> fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newImmutableFiniteIterable
by applying a function to all elements of thisImmutableFiniteIterable
.- Specified by:
fmap
in interfaceEnhancedIterable<A>
- Specified by:
fmap
in interfaceFiniteIterable<A>
- Specified by:
fmap
in interfacecom.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
- Specified by:
fmap
in interfaceImmutableIterable<A>
- Type Parameters:
B
- the type returned byf
- Parameters:
f
- a function fromA
toB
. This function should be referentially transparent and not perform side-effects. It may be called zero or more times for each element.- Returns:
- an
ImmutableFiniteIterable<B>
-
inits
default ImmutableNonEmptyFiniteIterable<? extends ImmutableFiniteIterable<A>> inits()
Returns anImmutableNonEmptyIterable
containing all of the subsequences of initial elements of thisImmutableFiniteIterable
, ordered by size, starting with the empty list. Example:ImmutableFiniteIterable.of(1, 2, 3).inits(); // [[], [1], [1, 2], [1, 2, 3]]
- Specified by:
inits
in interfaceFiniteIterable<A>
- Returns:
- an
ImmutableNonEmptyFiniteIterable<ImmutableFiniteIterable<A>>
-
intersperse
default ImmutableFiniteIterable<A> intersperse(A separator)
Returns a newImmutableFiniteIterable
with the provided separator value injected between each value of thisImmutableFiniteIterable
.If this
ImmutableFiniteIterable
contains fewer than two elements, it is left untouched.- Specified by:
intersperse
in interfaceEnhancedIterable<A>
- Specified by:
intersperse
in interfaceFiniteIterable<A>
- Specified by:
intersperse
in interfaceImmutableIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
ImmutableFiniteIterable<A>
-
magnetizeBy
default ImmutableFiniteIterable<? extends ImmutableNonEmptyFiniteIterable<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisImmutableFiniteIterable
that match a predicate pairwise.- Specified by:
magnetizeBy
in interfaceEnhancedIterable<A>
- Specified by:
magnetizeBy
in interfaceFiniteIterable<A>
- Specified by:
magnetizeBy
in interfaceImmutableIterable<A>
- Parameters:
predicate
- the predicate function. This function should be referentially transparent and not perform side-effects. It may be called zero or more times for each element.- Returns:
- an
ImmutableFiniteIterable<ImmutableNonEmptyFiniteIterable<A>>
containing the contiguous groups
-
partition
default <B,C> com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends ImmutableFiniteIterable<B>,? extends ImmutableFiniteIterable<C>> partition(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends com.jnape.palatable.lambda.adt.coproduct.CoProduct2<B,C,?>> function)
Partitions thisImmutableFiniteIterable
given a disjoint mapping function.- Specified by:
partition
in interfaceEnhancedIterable<A>
- Specified by:
partition
in interfaceFiniteIterable<A>
- Specified by:
partition
in interfaceImmutableIterable<A>
- Type Parameters:
B
- the output left Iterable element type, as well as the CoProduct2 A typeC
- the output right Iterable element type, as well as the CoProduct2 B type- Parameters:
function
- the mapping function- Returns:
- a
Tuple2<ImmutableFiniteIterable<B>, ImmutableFiniteIterable<C>>
-
prepend
default ImmutableNonEmptyFiniteIterable<A> prepend(A element)
Lazily prepends an element to the front of thisImmutableFiniteIterable
, yielding a newImmutableNonEmptyFiniteIterable
.- Specified by:
prepend
in interfaceEnhancedIterable<A>
- Specified by:
prepend
in interfaceFiniteIterable<A>
- Specified by:
prepend
in interfaceImmutableIterable<A>
- Parameters:
element
- the element to prepend- Returns:
- a
ImmutableNonEmptyFiniteIterable<A>
-
prependAll
default ImmutableFiniteIterable<A> prependAll(A separator)
Returns a newImmutableFiniteIterable
with the provided separator value injected before each value of thisImmutableFiniteIterable
.If this
ImmutableFiniteIterable
is empty, it is left untouched.- Specified by:
prependAll
in interfaceEnhancedIterable<A>
- Specified by:
prependAll
in interfaceFiniteIterable<A>
- Specified by:
prependAll
in interfaceImmutableIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
ImmutableFiniteIterable<A>
-
reverse
default ImmutableFiniteIterable<A> reverse()
Returns a reversed representation of thisImmutableFiniteIterable
.Note that reversing is deferred until the returned
Iterable
is iterated.- Specified by:
reverse
in interfaceFiniteIterable<A>
- Returns:
- an
ImmutableFiniteIterable<A>
-
slide
default ImmutableFiniteIterable<? extends ImmutableNonEmptyFiniteIterable<A>> slide(int k)
"Slides" a window ofk
elements across theImmutableFiniteIterable
by one element at a time.Example:
ImmutableFiniteIterable.of(1, 2, 3, 4, 5).slide(2); // [[1, 2], [2, 3], [3, 4], [4, 5]]
- Specified by:
slide
in interfaceEnhancedIterable<A>
- Specified by:
slide
in interfaceFiniteIterable<A>
- Specified by:
slide
in interfaceImmutableIterable<A>
- Parameters:
k
- the number of elements in the sliding window. Must be >= 1.- Returns:
- an
ImmutableFiniteIterable<ImmutableNonEmptyFiniteIterable<A>>
-
span
default com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends ImmutableFiniteIterable<A>,? extends ImmutableFiniteIterable<A>> span(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns aTuple2
where the first slot is the front contiguous elements of thisImmutableFiniteIterable
matching a predicate and the second slot is all the remaining elements.- Specified by:
span
in interfaceEnhancedIterable<A>
- Specified by:
span
in interfaceFiniteIterable<A>
- Specified by:
span
in interfaceImmutableIterable<A>
- Parameters:
predicate
- a predicate; should be referentially transparent and not have side-effects- Returns:
- a
Tuple2<ImmutableFiniteIterable<B>, ImmutableFiniteIterable<C>>
-
tails
default ImmutableNonEmptyIterable<? extends ImmutableFiniteIterable<A>> tails()
Returns anImmutableNonEmptyIterable
containing all of the subsequences of tail elements of thisImmutableFiniteIterable
, ordered by size, starting with the full list. Example:ImmutableFiniteIterable.of(1, 2, 3).tails(); // [[1, 2, 3], [2, 3], [3], []]
- Specified by:
tails
in interfaceEnhancedIterable<A>
- Specified by:
tails
in interfaceFiniteIterable<A>
- Specified by:
tails
in interfaceImmutableIterable<A>
- Returns:
- an
ImmutableNonEmptyIterable<ImmutableFiniteIterable<A>>
-
takeWhile
default ImmutableFiniteIterable<A> takeWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableFiniteIterable
that limits to the first contiguous group of elements of thisFiniteIterable
that satisfy a predicate.Iteration ends at, but does not include, the first element for which the predicate evaluates to false.
- Specified by:
takeWhile
in interfaceEnhancedIterable<A>
- Specified by:
takeWhile
in interfaceFiniteIterable<A>
- Specified by:
takeWhile
in interfaceImmutableIterable<A>
- Parameters:
predicate
- a predicate; should be referentially transparent and not have side-effects- Returns:
- a
ImmutableFiniteIterable<A>
-
toFinite
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableFiniteIterable<A>> toFinite()
Always succeeds becauseImmutableFiniteIterable
s are always finite.- Specified by:
toFinite
in interfaceEnhancedIterable<A>
- Specified by:
toFinite
in interfaceFiniteIterable<A>
- Specified by:
toFinite
in interfaceImmutableIterable<A>
- Returns:
- this
ImmutableFiniteIterable
wrapped in a `just`
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyFiniteIterable<A>> toNonEmpty()
Converts thisImmutableFiniteIterable
to aImmutableNonEmptyFiniteIterable
if it contains one or more elements.- Specified by:
toNonEmpty
in interfaceEnhancedIterable<A>
- Specified by:
toNonEmpty
in interfaceFiniteIterable<A>
- Specified by:
toNonEmpty
in interfaceImmutableIterable<A>
- Returns:
- a
Maybe<ImmutableNonEmptyFiniteIterable<A>
-
zipWith
default <B,C> ImmutableFiniteIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableIterable<B> other)
Zips together thisImmutableFiniteIterable
with anotherImmutableIterable
by applying a zipping function.Applies the function to the successive elements of each
Iterable
until one of them runs out of elements.- Specified by:
zipWith
in interfaceImmutableIterable<A>
- Type Parameters:
B
- the element type of the otherIterable
C
- the element type of the result- Parameters:
fn
- the zipping function. Not null. This function should be referentially transparent and not perform side-effects. It may be called zero or more times for each element.other
- the otherIterable
- Returns:
- an
ImmutableFiniteIterable<C>
-
copyFrom
static <A> ImmutableFiniteIterable<A> copyFrom(FiniteIterable<A> source)
Creates anImmutableFiniteIterable
by copying elements from aFiniteIterable
.If
source
is already anImmutableFiniteIterable
, this method will return it without copying.- Type Parameters:
A
- the element type- Parameters:
source
- the source to copy from- Returns:
- an
ImmutableFiniteIterable<A>
-
copyFrom
static <A> ImmutableFiniteIterable<A> copyFrom(java.util.Collection<A> source)
Creates anImmutableFiniteIterable
by copying elements from aCollection
.- Type Parameters:
A
- the element type- Parameters:
source
- the source to copy from- Returns:
- an
ImmutableFiniteIterable<A>
-
copyFrom
static <A> ImmutableFiniteIterable<A> copyFrom(int maxCount, java.lang.Iterable<A> source)
Creates anImmutableFiniteIterable
by copying elements from anIterable
.If
source
is already anImmutableIterable
, no copying will be performed.- Type Parameters:
A
- the element type- Parameters:
maxCount
- the maximum number of elements to take from the suppliedIterable
. Must be >= 0. May exceed size of theIterable
, in which case, the result will contain as many elements available.source
- the source to copy from- Returns:
- an
ImmutableFiniteIterable<A>
-
emptyImmutableFiniteIterable
static <A> ImmutableFiniteIterable<A> emptyImmutableFiniteIterable()
Creates an emptyImmutableFiniteIterable
.- Type Parameters:
A
- the element type- Returns:
- an
ImmutableFiniteIterable<A>
-
of
@SafeVarargs static <A> ImmutableNonEmptyFiniteIterable<A> of(A first, A... more)
Creates anImmutableFiniteIterable
containing the given elements.Note that this method actually returns an
ImmutableNonEmptyFiniteIterable
, which is also anImmutableFiniteIterable
.- Type Parameters:
A
- the element type- Parameters:
first
- the first elementmore
- the remaining elements- Returns:
- an
ImmutableNonEmptyFiniteIterable<A>
-
-