Package software.kes.enhancediterables
Interface ImmutableNonEmptyIterable<A>
-
- Type Parameters:
A
- the element type
- All Superinterfaces:
EnhancedIterable<A>
,com.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
,ImmutableIterable<A>
,java.lang.Iterable<A>
,NonEmptyIterable<A>
- All Known Subinterfaces:
ImmutableNonEmptyFiniteIterable<A>
public interface ImmutableNonEmptyIterable<A> extends ImmutableIterable<A>, NonEmptyIterable<A>
AnEnhancedIterable
that is safe from mutation, and 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 ImmutableNonEmptyIterable<A>
concat(ImmutableIterable<A> other)
Lazily concatenates anImmutableIterable
to the end of thisImmutableNonEmptyIterable
, yielding a newImmutableNonEmptyIterable
.default <B> ImmutableNonEmptyIterable<B>
fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newImmutableNonEmptyIterable
by applying a function to all elements of thisImmutableNonEmptyIterable
.static <A> ImmutableNonEmptyIterable<A>
immutableNonEmptyIterable(A head, ImmutableIterable<A> tail)
Creates anImmutableNonEmptyIterable
.default ImmutableNonEmptyIterable<A>
intersperse(A separator)
Returns a newImmutableNonEmptyIterable
with the provided separator value injected between each value of thisImmutableNonEmptyIterable
.default ImmutableNonEmptyIterable<? extends ImmutableNonEmptyIterable<A>>
magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisImmutableNonEmptyIterable
that match a predicate pairwise.static <A> ImmutableNonEmptyFiniteIterable<A>
of(A first, A... more)
Creates anImmutableNonEmptyIterable
containing the given elements.default ImmutableNonEmptyIterable<A>
prependAll(A separator)
Returns a newImmutableNonEmptyIterable
with the provided separator value injected before each value of thisImmutableNonEmptyIterable
.static <A> ImmutableNonEmptyIterable<A>
repeat(A element)
Returns an infiniteImmutableNonEmptyIterable
that repeatedly iterates a given element.ImmutableIterable<A>
tail()
Returns anImmutableIterable
containing all subsequent elements of this one beyond the first.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyFiniteIterable<A>>
toFinite()
Converts thisImmutableNonEmptyIterable
to anImmutableNonEmptyFiniteIterable
if there is enough information to do so without iterating it.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyIterable<A>>
toNonEmpty()
Always succeeds becauseImmutableNonEmptyFiniteIterable
s are always non-empty.default <B,C>
ImmutableNonEmptyFiniteIterable<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyFiniteIterable<B> other)
Zips together thisImmutableNonEmptyIterable
with anImmutableNonEmptyFiniteIterable
by applying a zipping function.default <B,C>
ImmutableNonEmptyIterable<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyIterable<B> other)
Zips together thisImmutableNonEmptyIterable
with anotherImmutableNonEmptyIterable
by applying a zipping function.-
Methods inherited from interface software.kes.enhancediterables.EnhancedIterable
concat, find, toArray, toCollection, zipWith, zipWith, zipWith
-
-
-
-
Method Detail
-
tail
ImmutableIterable<A> tail()
Returns anImmutableIterable
containing all subsequent elements of this one beyond the first.- Specified by:
tail
in interfaceNonEmptyIterable<A>
- Returns:
- an
ImmutableIterable<A>
-
concat
default ImmutableNonEmptyIterable<A> concat(ImmutableIterable<A> other)
Lazily concatenates anImmutableIterable
to the end of thisImmutableNonEmptyIterable
, yielding a newImmutableNonEmptyIterable
.- Specified by:
concat
in interfaceImmutableIterable<A>
- Parameters:
other
- anImmutableIterable
- Returns:
- an
ImmutableNonEmptyIterable<A>
-
fmap
default <B> ImmutableNonEmptyIterable<B> fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Returns a newImmutableNonEmptyIterable
by applying a function to all elements of thisImmutableNonEmptyIterable
.- Specified by:
fmap
in interfaceEnhancedIterable<A>
- Specified by:
fmap
in interfacecom.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>
- Specified by:
fmap
in interfaceImmutableIterable<A>
- 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:
- an
ImmutableNonEmptyIterable<B>
-
intersperse
default ImmutableNonEmptyIterable<A> intersperse(A separator)
Returns a newImmutableNonEmptyIterable
with the provided separator value injected between each value of thisImmutableNonEmptyIterable
.If this
ImmutableNonEmptyIterable
contains only one element, it is left untouched.- Specified by:
intersperse
in interfaceEnhancedIterable<A>
- Specified by:
intersperse
in interfaceImmutableIterable<A>
- Specified by:
intersperse
in interfaceNonEmptyIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
ImmutableNonEmptyIterable<A>
-
magnetizeBy
default ImmutableNonEmptyIterable<? extends ImmutableNonEmptyIterable<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterable
of contiguous groups of elements in thisImmutableNonEmptyIterable
that match a predicate pairwise.- Specified by:
magnetizeBy
in interfaceEnhancedIterable<A>
- Specified by:
magnetizeBy
in interfaceImmutableIterable<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
ImmutableNonEmptyIterable<ImmutableNonEmptyIterable<A>>
containing the contiguous groups
-
prependAll
default ImmutableNonEmptyIterable<A> prependAll(A separator)
Returns a newImmutableNonEmptyIterable
with the provided separator value injected before each value of thisImmutableNonEmptyIterable
.- Specified by:
prependAll
in interfaceEnhancedIterable<A>
- Specified by:
prependAll
in interfaceImmutableIterable<A>
- Specified by:
prependAll
in interfaceNonEmptyIterable<A>
- Parameters:
separator
- the separator value- Returns:
- a
ImmutableNonEmptyIterable<A>
-
toFinite
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyFiniteIterable<A>> toFinite()
Converts thisImmutableNonEmptyIterable
to anImmutableNonEmptyFiniteIterable
if there is enough information to do so without iterating it.Note that if this method returns
nothing()
, it does NOT necessarily mean thisImmutableNonEmptyIterable
is infinite.- Specified by:
toFinite
in interfaceEnhancedIterable<A>
- Specified by:
toFinite
in interfaceImmutableIterable<A>
- Specified by:
toFinite
in interfaceNonEmptyIterable<A>
- Returns:
- a
Maybe<ImmutableNonEmptyFiniteIterable<A>
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyIterable<A>> toNonEmpty()
Always succeeds becauseImmutableNonEmptyFiniteIterable
s are always non-empty.- Specified by:
toNonEmpty
in interfaceEnhancedIterable<A>
- Specified by:
toNonEmpty
in interfaceImmutableIterable<A>
- Specified by:
toNonEmpty
in interfaceNonEmptyIterable<A>
- Returns:
- this
ImmutableNonEmptyFiniteIterable
wrapped in a `just`
-
zipWith
default <B,C> ImmutableNonEmptyIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyIterable<B> other)
Zips together thisImmutableNonEmptyIterable
with anotherImmutableNonEmptyIterable
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
ImmutableNonEmptyIterable<C>
-
zipWith
default <B,C> ImmutableNonEmptyFiniteIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyFiniteIterable<B> other)
Zips together thisImmutableNonEmptyIterable
with anImmutableNonEmptyFiniteIterable
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
ImmutableNonEmptyFiniteIterable<C>
-
immutableNonEmptyIterable
static <A> ImmutableNonEmptyIterable<A> immutableNonEmptyIterable(A head, ImmutableIterable<A> tail)
Creates anImmutableNonEmptyIterable
.- Type Parameters:
A
- the element type- Parameters:
head
- the first elementtail
- the remaining elements. May be empty.- Returns:
- a
ImmutableNonEmptyIterable<A>
-
of
@SafeVarargs static <A> ImmutableNonEmptyFiniteIterable<A> of(A first, A... more)
Creates anImmutableNonEmptyIterable
containing the given elements.Note that this method actually returns an
ImmutableNonEmptyFiniteIterable
, which is also anImmutableNonEmptyIterable
.- 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>
-
-