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>
AnEnhancedIterablethat 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 aCollectionto the end of thisNonEmptyFiniteIterable, yielding a newNonEmptyFiniteIterable.default NonEmptyFiniteIterable<A>concat(FiniteIterable<A> other)Lazily concatenates aFiniteIterableto 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 thisNonEmptyFiniteIterablewith anotherNonEmptyFiniteIterable.default NonEmptyIterable<A>cycle()Returns an infiniteNonEmptyIterablethat repeatedly cycles thisNonEmptyFiniteIterable's elements, in order.default NonEmptyFiniteIterable<A>distinct()Returns aNonEmptyFiniteIterableof the distinct values from thisNonEmptyFiniteIterable.default <B> NonEmptyFiniteIterable<B>fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)Returns a newNonEmptyFiniteIterableby applying a function to all elements of thisNonEmptyFiniteIterable.default FiniteIterable<A>init()Returns aFiniteIterablecontaining all of elements of this one, except for the last element.default NonEmptyFiniteIterable<A>intersperse(A separator)Returns a newNonEmptyFiniteIterablewith the provided separator value injected between each value of thisNonEmptyFiniteIterable.default Alast()Returns the last element.default NonEmptyFiniteIterable<? extends NonEmptyFiniteIterable<A>>magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)Returns anIterableof contiguous groups of elements in thisNonEmptyFiniteIterablethat 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 aNonEmptyFiniteIterablecontaining the given elements.default NonEmptyFiniteIterable<A>prependAll(A separator)Returns a newNonEmptyFiniteIterablewith the provided separator value injected before each value of thisNonEmptyFiniteIterable.default AreduceLeft(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 AreduceRight(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 anFiniteIterablecontaining all subsequent elements of this one beyond the first.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>>toFinite()Always succeeds becauseNonEmptyFiniteIterables are always finite.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>>toNonEmpty()Always succeeds becauseNonEmptyFiniteIterables 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 thisNonEmptyFiniteIterablewith anNonEmptyIterableby 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 anFiniteIterablecontaining all subsequent elements of this one beyond the first.- Specified by:
tailin interfaceNonEmptyIterable<A>- Returns:
- an
FiniteIterable<A>
-
concat
default NonEmptyFiniteIterable<A> concat(FiniteIterable<A> other)
Lazily concatenates aFiniteIterableto the end of thisNonEmptyFiniteIterable, yielding a newNonEmptyFiniteIterable.- Specified by:
concatin interfaceFiniteIterable<A>- Parameters:
other- aFiniteIterable- Returns:
- an
NonEmptyFiniteIterable<A>
-
concat
default NonEmptyFiniteIterable<A> concat(java.util.Collection<A> other)
Lazily concatenates aCollectionto the end of thisNonEmptyFiniteIterable, yielding a newNonEmptyFiniteIterable.- Specified by:
concatin 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 thisNonEmptyFiniteIterablewith anotherNonEmptyFiniteIterable.- Type Parameters:
B- the type of the otherNonEmptyFiniteIterable- Parameters:
other- aNonEmptyFiniteIterableof any type- Returns:
- a
NonEmptyFiniteIterable<Tuple2<A, B>>
-
cycle
default NonEmptyIterable<A> cycle()
Returns an infiniteNonEmptyIterablethat repeatedly cycles thisNonEmptyFiniteIterable's elements, in order.- Specified by:
cyclein interfaceFiniteIterable<A>- Returns:
- an
NonEmptyIterable<A>
-
distinct
default NonEmptyFiniteIterable<A> distinct()
Returns aNonEmptyFiniteIterableof the distinct values from thisNonEmptyFiniteIterable.- Specified by:
distinctin 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 newNonEmptyFiniteIterableby applying a function to all elements of thisNonEmptyFiniteIterable.- Specified by:
fmapin interfaceEnhancedIterable<A>- Specified by:
fmapin interfaceFiniteIterable<A>- Specified by:
fmapin interfacecom.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>- Specified by:
fmapin interfaceNonEmptyIterable<A>- Type Parameters:
B- the type returned byf- Parameters:
f- a function fromAtoB. 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 aFiniteIterablecontaining all of elements of this one, except for the last element.- Returns:
- a
FiniteIterable<A>
-
intersperse
default NonEmptyFiniteIterable<A> intersperse(A separator)
Returns a newNonEmptyFiniteIterablewith the provided separator value injected between each value of thisNonEmptyFiniteIterable.If this
NonEmptyFiniteIterablecontains only one element, it is left untouched.- Specified by:
interspersein interfaceEnhancedIterable<A>- Specified by:
interspersein interfaceFiniteIterable<A>- Specified by:
interspersein 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 anIterableof contiguous groups of elements in thisNonEmptyFiniteIterablethat match a predicate pairwise.- Specified by:
magnetizeByin interfaceEnhancedIterable<A>- Specified by:
magnetizeByin interfaceFiniteIterable<A>- Specified by:
magnetizeByin 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 newNonEmptyFiniteIterablewith the provided separator value injected before each value of thisNonEmptyFiniteIterable.- Specified by:
prependAllin interfaceEnhancedIterable<A>- Specified by:
prependAllin interfaceFiniteIterable<A>- Specified by:
prependAllin 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
opbetween 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
opbetween 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
Iterableis iterated.- Specified by:
reversein interfaceFiniteIterable<A>- Returns:
- a
NonEmptyFiniteIterable<A>
-
toFinite
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toFinite()
Always succeeds becauseNonEmptyFiniteIterables are always finite.- Specified by:
toFinitein interfaceEnhancedIterable<A>- Specified by:
toFinitein interfaceFiniteIterable<A>- Specified by:
toFinitein interfaceNonEmptyIterable<A>- Returns:
- this
NonEmptyFiniteIterablewrapped in a `just`
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toNonEmpty()
Always succeeds becauseNonEmptyFiniteIterables are always non-empty.- Specified by:
toNonEmptyin interfaceEnhancedIterable<A>- Specified by:
toNonEmptyin interfaceFiniteIterable<A>- Specified by:
toNonEmptyin interfaceNonEmptyIterable<A>- Returns:
- this
NonEmptyFiniteIterablewrapped 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 thisNonEmptyFiniteIterablewith anNonEmptyIterableby applying a zipping function.Applies the function to the successive elements of each
Iterableuntil one of them runs out of elements.- Specified by:
zipWithin interfaceNonEmptyIterable<A>- Type Parameters:
B- the element type of the otherIterableC- 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 aNonEmptyFiniteIterablecontaining 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>
-
-