Package software.kes.enhancediterables
Interface NonEmptyIterable<A>
-
- Type Parameters:
A
- the element type
- All Superinterfaces:
EnhancedIterable<A>
,com.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
,java.lang.Iterable<A>
- All Known Subinterfaces:
ImmutableNonEmptyFiniteIterable<A>
,ImmutableNonEmptyIterable<A>
,NonEmptyFiniteIterable<A>
public interface NonEmptyIterable<A> extends EnhancedIterable<A>
AnEnhancedIterable
that is guaranteed to contain at least one element.May be infinite or finite.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default NonEmptyIterable<A>
concat(java.lang.Iterable<A> other)
Lazily concatenates anIterable
to the end of thisNonEmptyIterable
, yielding a newNonEmptyIterable
.default <B> NonEmptyIterable<B>
fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newNonEmptyIterable
by applying a function to all elements of thisNonEmptyIterable
.A
head()
Returns the first element.default NonEmptyIterable<A>
intersperse(A separator)
Returns a newNonEmptyIterable
with the provided separator value injected between each value of thisNonEmptyIterable
.default boolean
isEmpty()
Always returns false, as aNonEmptyIterable
is never empty.default java.util.Iterator<A>
iterator()
default NonEmptyIterable<? extends NonEmptyIterable<A>>
magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisNonEmptyIterable
that match a predicate pairwise.static <A> NonEmptyIterable<A>
nonEmptyIterable(A head, java.lang.Iterable<A> tail)
Creates aNonEmptyIterable
.static <A> ImmutableNonEmptyFiniteIterable<A>
of(A first, A... more)
Creates aNonEmptyIterable
containing the given elements.default NonEmptyIterable<A>
prependAll(A separator)
Returns a newNonEmptyIterable
with the provided separator value injected before each value of thisNonEmptyIterable
.static <A> ImmutableNonEmptyIterable<A>
repeat(A element)
Returns an infiniteImmutableNonEmptyIterable
that repeatedly iterates a given element.EnhancedIterable<A>
tail()
Returns anEnhancedIterable
containing all subsequent elements of this one beyond the first.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>>
toFinite()
Converts thisNonEmptyIterable
to anNonEmptyFiniteIterable
if there is enough information to do so without iterating it.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyIterable<A>>
toNonEmpty()
Always succeeds becauseNonEmptyIterable
s are always non-empty.default <B,C>
NonEmptyFiniteIterable<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyFiniteIterable<B> other)
Zips together thisNonEmptyIterable
with aNonEmptyFiniteIterable
by applying a zipping function.default <B,C>
NonEmptyIterable<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyIterable<B> other)
Zips together thisNonEmptyIterable
with anotherNonEmptyIterable
by applying a zipping function.
-
-
-
Method Detail
-
head
A head()
Returns the first element.- Returns:
- an element of type
A
-
tail
EnhancedIterable<A> tail()
Returns anEnhancedIterable
containing all subsequent elements of this one beyond the first.- Returns:
- an
EnhancedIterable<A>
-
concat
default NonEmptyIterable<A> concat(java.lang.Iterable<A> other)
Lazily concatenates anIterable
to the end of thisNonEmptyIterable
, yielding a newNonEmptyIterable
.- Specified by:
concat
in interfaceEnhancedIterable<A>
- Parameters:
other
- anIterable
- Returns:
- a
NonEmptyIterable<A>
-
fmap
default <B> NonEmptyIterable<B> fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newNonEmptyIterable
by applying a function to all elements of thisNonEmptyIterable
.- Specified by:
fmap
in interfaceEnhancedIterable<A>
- Specified by:
fmap
in interfacecom.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
- 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
NonEmptyIterable<B>
-
isEmpty
default boolean isEmpty()
Always returns false, as aNonEmptyIterable
is never empty.- Specified by:
isEmpty
in interfaceEnhancedIterable<A>
- Returns:
- false
-
intersperse
default NonEmptyIterable<A> intersperse(A separator)
Returns a newNonEmptyIterable
with the provided separator value injected between each value of thisNonEmptyIterable
.If this
NonEmptyIterable
contains only one element, it is left untouched.- Specified by:
intersperse
in interfaceEnhancedIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
NonEmptyIterable<A>
-
iterator
default java.util.Iterator<A> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<A>
-
magnetizeBy
default NonEmptyIterable<? extends NonEmptyIterable<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisNonEmptyIterable
that match a predicate pairwise.- Specified by:
magnetizeBy
in interfaceEnhancedIterable<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
NonEmptyIterable<NonEmptyIterable<A>>
containing the contiguous groups
-
prependAll
default NonEmptyIterable<A> prependAll(A separator)
Returns a newNonEmptyIterable
with the provided separator value injected before each value of thisNonEmptyIterable
.- Specified by:
prependAll
in interfaceEnhancedIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
NonEmptyIterable<A>
-
toFinite
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toFinite()
Converts thisNonEmptyIterable
to anNonEmptyFiniteIterable
if there is enough information to do so without iterating it.Note that if this method returns
nothing()
, it does NOT necessarily mean thisNonEmptyIterable
is infinite.- Specified by:
toFinite
in interfaceEnhancedIterable<A>
- Returns:
- a
Maybe<NonEmptyFiniteIterable<A>
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyIterable<A>> toNonEmpty()
Always succeeds becauseNonEmptyIterable
s are always non-empty.- Specified by:
toNonEmpty
in interfaceEnhancedIterable<A>
- Returns:
- this
NonEmptyIterable
wrapped in a `just`
-
zipWith
default <B,C> NonEmptyIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyIterable<B> other)
Zips together thisNonEmptyIterable
with anotherNonEmptyIterable
by applying a zipping function.Applies the function to the successive elements of each
Iterable
until one of them runs out of elements.- 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
NonEmptyIterable<C>
-
zipWith
default <B,C> NonEmptyFiniteIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyFiniteIterable<B> other)
Zips together thisNonEmptyIterable
with aNonEmptyFiniteIterable
by applying a zipping function.Applies the function to the successive elements of each
Iterable
until one of them runs out of elements.- 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>
-
nonEmptyIterable
static <A> NonEmptyIterable<A> nonEmptyIterable(A head, java.lang.Iterable<A> tail)
Creates aNonEmptyIterable
.- Type Parameters:
A
- the element type- Parameters:
head
- the first elementtail
- the remaining elements. May be empty.- Returns:
- a
NonEmptyIterable<A>
-
of
@SafeVarargs static <A> ImmutableNonEmptyFiniteIterable<A> of(A first, A... more)
Creates aNonEmptyIterable
containing the given elements.Note that this method actually returns an
ImmutableNonEmptyFiniteIterable
, which is also aNonEmptyIterable
.- Type Parameters:
A
- the element type- Parameters:
first
- the first elementmore
- the remaining elements- Returns:
- an
ImmutableNonEmptyFiniteIterable<A>
-
repeat
static <A> ImmutableNonEmptyIterable<A> repeat(A element)
Returns an infiniteImmutableNonEmptyIterable
that repeatedly iterates a given element.- Type Parameters:
A
- the element type- Parameters:
element
- the value to repeat- Returns:
- an
ImmutableNonEmptyIterable<A>
-
-