Package software.kes.enhancediterables
Interface NonEmptyFiniteIterable<A>
-
- Type Parameters:
A
- the element type
- All Superinterfaces:
EnhancedIterable<A>
,FiniteIterable<A>
,com.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
,java.lang.Iterable<A>
,NonEmptyIterable<A>
- All Known Subinterfaces:
ImmutableNonEmptyFiniteIterable<A>
public interface NonEmptyFiniteIterable<A> extends FiniteIterable<A>, NonEmptyIterable<A>
AnEnhancedIterable
that is finite and guaranteed to contain at least one element.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default NonEmptyFiniteIterable<A>
concat(java.util.Collection<A> other)
Lazily concatenates aCollection
to the end of thisNonEmptyFiniteIterable
, yielding a newNonEmptyFiniteIterable
.default NonEmptyFiniteIterable<A>
concat(FiniteIterable<A> other)
Lazily concatenates aFiniteIterable
to the end of thisNonEmptyFiniteIterable
, yielding a newNonEmptyFiniteIterable
.default <B> NonEmptyFiniteIterable<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>>
cross(NonEmptyFiniteIterable<B> other)
Returns the lazily computed cartesian product of thisNonEmptyFiniteIterable
with anotherNonEmptyFiniteIterable
.default NonEmptyIterable<A>
cycle()
Returns an infiniteNonEmptyIterable
that repeatedly cycles thisNonEmptyFiniteIterable
's elements, in order.default NonEmptyFiniteIterable<A>
distinct()
Returns aNonEmptyFiniteIterable
of the distinct values from thisNonEmptyFiniteIterable
.default <B> NonEmptyFiniteIterable<B>
fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newNonEmptyFiniteIterable
by applying a function to all elements of thisNonEmptyFiniteIterable
.default FiniteIterable<A>
init()
Returns aFiniteIterable
containing all of elements of this one, except for the last element.default NonEmptyFiniteIterable<A>
intersperse(A separator)
Returns a newNonEmptyFiniteIterable
with the provided separator value injected between each value of thisNonEmptyFiniteIterable
.default A
last()
Returns the last element.default NonEmptyFiniteIterable<? extends NonEmptyFiniteIterable<A>>
magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisNonEmptyFiniteIterable
that match a predicate pairwise.static <A> NonEmptyFiniteIterable<A>
nonEmptyFiniteIterable(A head, java.util.Collection<A> tail)
Creates aNonEmptyFiniteIterable
.static <A> NonEmptyFiniteIterable<A>
nonEmptyFiniteIterable(A head, FiniteIterable<A> tail)
Creates aNonEmptyFiniteIterable
.static <A> ImmutableNonEmptyFiniteIterable<A>
of(A first, A... more)
Creates aNonEmptyFiniteIterable
containing the given elements.default NonEmptyFiniteIterable<A>
prependAll(A separator)
Returns a newNonEmptyFiniteIterable
with the provided separator value injected before each value of thisNonEmptyFiniteIterable
.default A
reduceLeft(com.jnape.palatable.lambda.functions.Fn2<? super A,? super A,? extends A> op)
Applies a binary operator to all elements of thisNonEmptyFiniteIterable
, going left to right.default A
reduceRight(com.jnape.palatable.lambda.functions.Fn2<? super A,? super A,? extends A> op)
Applies a binary operator to all elements of thisNonEmptyFiniteIterable
, going right to left.default NonEmptyFiniteIterable<A>
reverse()
Returns a reversed representation of thisNonEmptyFiniteIterable
.FiniteIterable<A>
tail()
Returns anFiniteIterable
containing all subsequent elements of this one beyond the first.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>>
toFinite()
Always succeeds becauseNonEmptyFiniteIterable
s are always finite.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>>
toNonEmpty()
Always succeeds becauseNonEmptyFiniteIterable
s are always non-empty.default <B,C>
NonEmptyFiniteIterable<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyIterable<B> other)
Zips together thisNonEmptyFiniteIterable
with anNonEmptyIterable
by applying a zipping function.-
Methods inherited from interface software.kes.enhancediterables.EnhancedIterable
concat, find, take, toArray, toCollection, zipWith, zipWith
-
-
-
-
Method Detail
-
tail
FiniteIterable<A> tail()
Returns anFiniteIterable
containing all subsequent elements of this one beyond the first.- Specified by:
tail
in interfaceNonEmptyIterable<A>
- Returns:
- an
FiniteIterable<A>
-
concat
default NonEmptyFiniteIterable<A> concat(FiniteIterable<A> other)
Lazily concatenates aFiniteIterable
to the end of thisNonEmptyFiniteIterable
, yielding a newNonEmptyFiniteIterable
.- Specified by:
concat
in interfaceFiniteIterable<A>
- Parameters:
other
- aFiniteIterable
- Returns:
- an
NonEmptyFiniteIterable<A>
-
concat
default NonEmptyFiniteIterable<A> concat(java.util.Collection<A> other)
Lazily concatenates aCollection
to the end of thisNonEmptyFiniteIterable
, yielding a newNonEmptyFiniteIterable
.- Specified by:
concat
in interfaceFiniteIterable<A>
- Parameters:
other
- aCollection
- Returns:
- an
NonEmptyFiniteIterable<A>
-
cross
default <B> NonEmptyFiniteIterable<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>> cross(NonEmptyFiniteIterable<B> other)
Returns the lazily computed cartesian product of thisNonEmptyFiniteIterable
with anotherNonEmptyFiniteIterable
.- Type Parameters:
B
- the type of the otherNonEmptyFiniteIterable
- Parameters:
other
- aNonEmptyFiniteIterable
of any type- Returns:
- a
NonEmptyFiniteIterable<Tuple2<A, B>>
-
cycle
default NonEmptyIterable<A> cycle()
Returns an infiniteNonEmptyIterable
that repeatedly cycles thisNonEmptyFiniteIterable
's elements, in order.- Specified by:
cycle
in interfaceFiniteIterable<A>
- Returns:
- an
NonEmptyIterable<A>
-
distinct
default NonEmptyFiniteIterable<A> distinct()
Returns aNonEmptyFiniteIterable
of the distinct values from thisNonEmptyFiniteIterable
.- Specified by:
distinct
in interfaceFiniteIterable<A>
- Returns:
- a
NonEmptyFiniteIterable<A>
-
fmap
default <B> NonEmptyFiniteIterable<B> fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newNonEmptyFiniteIterable
by applying a function to all elements of thisNonEmptyFiniteIterable
.- 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 interfaceNonEmptyIterable<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:
- a
NonEmptyFiniteIterable<B>
-
init
default FiniteIterable<A> init()
Returns aFiniteIterable
containing all of elements of this one, except for the last element.- Returns:
- a
FiniteIterable<A>
-
intersperse
default NonEmptyFiniteIterable<A> intersperse(A separator)
Returns a newNonEmptyFiniteIterable
with the provided separator value injected between each value of thisNonEmptyFiniteIterable
.If this
NonEmptyFiniteIterable
contains only one element, it is left untouched.- Specified by:
intersperse
in interfaceEnhancedIterable<A>
- Specified by:
intersperse
in interfaceFiniteIterable<A>
- Specified by:
intersperse
in interfaceNonEmptyIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
NonEmptyFiniteIterable<A>
-
last
default A last()
Returns the last element.- Returns:
- an element of type
A
-
magnetizeBy
default NonEmptyFiniteIterable<? extends NonEmptyFiniteIterable<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisNonEmptyFiniteIterable
that match a predicate pairwise.- Specified by:
magnetizeBy
in interfaceEnhancedIterable<A>
- Specified by:
magnetizeBy
in interfaceFiniteIterable<A>
- Specified by:
magnetizeBy
in interfaceNonEmptyIterable<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
NonEmptyFiniteIterable<NonEmptyFiniteIterable<A>>
containing the contiguous groups
-
prependAll
default NonEmptyFiniteIterable<A> prependAll(A separator)
Returns a newNonEmptyFiniteIterable
with the provided separator value injected before each value of thisNonEmptyFiniteIterable
.- Specified by:
prependAll
in interfaceEnhancedIterable<A>
- Specified by:
prependAll
in interfaceFiniteIterable<A>
- Specified by:
prependAll
in interfaceNonEmptyIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
NonEmptyFiniteIterable<A>
-
reduceLeft
default A reduceLeft(com.jnape.palatable.lambda.functions.Fn2<? super A,? super A,? extends A> op)
Applies a binary operator to all elements of thisNonEmptyFiniteIterable
, going left to right.- Parameters:
op
- the binary operator (accumulator on the left, item on the right)- Returns:
- the result of inserting
op
between consecutive elements of thisNonEmptyFiniteIterable
, going left to right:op( op( ... op(x_1, x_2) ..., x_{n-1}), x_n)
wherex,,1,,, ..., x,,n,,
are the elements of thisNonEmptyFiniteIterable
-
reduceRight
default A reduceRight(com.jnape.palatable.lambda.functions.Fn2<? super A,? super A,? extends A> op)
Applies a binary operator to all elements of thisNonEmptyFiniteIterable
, going right to left.- Parameters:
op
- the binary operator (item on the left, accumulator on the right)- Returns:
- the result of inserting
op
between consecutive elements of thisNonEmptyFiniteIterable
, going right to left:op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...))
wherex,,1,,, ..., x,,n,,
are the elements of thisNonEmptyFiniteIterable
-
reverse
default NonEmptyFiniteIterable<A> reverse()
Returns a reversed representation of thisNonEmptyFiniteIterable
.Note that reversing is deferred until the returned
Iterable
is iterated.- Specified by:
reverse
in interfaceFiniteIterable<A>
- Returns:
- a
NonEmptyFiniteIterable<A>
-
toFinite
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toFinite()
Always succeeds becauseNonEmptyFiniteIterable
s are always finite.- Specified by:
toFinite
in interfaceEnhancedIterable<A>
- Specified by:
toFinite
in interfaceFiniteIterable<A>
- Specified by:
toFinite
in interfaceNonEmptyIterable<A>
- Returns:
- this
NonEmptyFiniteIterable
wrapped in a `just`
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toNonEmpty()
Always succeeds becauseNonEmptyFiniteIterable
s are always non-empty.- Specified by:
toNonEmpty
in interfaceEnhancedIterable<A>
- Specified by:
toNonEmpty
in interfaceFiniteIterable<A>
- Specified by:
toNonEmpty
in interfaceNonEmptyIterable<A>
- Returns:
- this
NonEmptyFiniteIterable
wrapped in a `just`
-
zipWith
default <B,C> NonEmptyFiniteIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyIterable<B> other)
Zips together thisNonEmptyFiniteIterable
with anNonEmptyIterable
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 interfaceNonEmptyIterable<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
NonEmptyFiniteIterable<C>
-
nonEmptyFiniteIterable
static <A> NonEmptyFiniteIterable<A> nonEmptyFiniteIterable(A head, FiniteIterable<A> tail)
Creates aNonEmptyFiniteIterable
.- Type Parameters:
A
- the element type- Parameters:
head
- the first elementtail
- the remaining elements. May be empty.- Returns:
- a
NonEmptyFiniteIterable<A>
-
nonEmptyFiniteIterable
static <A> NonEmptyFiniteIterable<A> nonEmptyFiniteIterable(A head, java.util.Collection<A> tail)
Creates aNonEmptyFiniteIterable
.- Type Parameters:
A
- the element type- Parameters:
head
- the first elementtail
- the remaining elements. May be empty.- Returns:
- a
NonEmptyFiniteIterable<A>
-
of
@SafeVarargs static <A> ImmutableNonEmptyFiniteIterable<A> of(A first, A... more)
Creates aNonEmptyFiniteIterable
containing the given elements.Note that this method actually returns an
ImmutableNonEmptyFiniteIterable
, which is also anNonEmptyFiniteIterable
.- Type Parameters:
A
- the element type- Parameters:
first
- the first elementmore
- the remaining elements- Returns:
- an
ImmutableNonEmptyFiniteIterable<A>
-
-