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>
AnEnhancedIterablethat 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 anIterableto 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 newNonEmptyIterableby applying a function to all elements of thisNonEmptyIterable.Ahead()Returns the first element.default NonEmptyIterable<A>intersperse(A separator)Returns a newNonEmptyIterablewith the provided separator value injected between each value of thisNonEmptyIterable.default booleanisEmpty()Always returns false, as aNonEmptyIterableis 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 anIterableof contiguous groups of elements in thisNonEmptyIterablethat 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 aNonEmptyIterablecontaining the given elements.default NonEmptyIterable<A>prependAll(A separator)Returns a newNonEmptyIterablewith the provided separator value injected before each value of thisNonEmptyIterable.static <A> ImmutableNonEmptyIterable<A>repeat(A element)Returns an infiniteImmutableNonEmptyIterablethat repeatedly iterates a given element.EnhancedIterable<A>tail()Returns anEnhancedIterablecontaining all subsequent elements of this one beyond the first.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>>toFinite()Converts thisNonEmptyIterableto anNonEmptyFiniteIterableif there is enough information to do so without iterating it.default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyIterable<A>>toNonEmpty()Always succeeds becauseNonEmptyIterables 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 thisNonEmptyIterablewith aNonEmptyFiniteIterableby 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 thisNonEmptyIterablewith anotherNonEmptyIterableby applying a zipping function.
-
-
-
Method Detail
-
head
A head()
Returns the first element.- Returns:
- an element of type
A
-
tail
EnhancedIterable<A> tail()
Returns anEnhancedIterablecontaining 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 anIterableto the end of thisNonEmptyIterable, yielding a newNonEmptyIterable.- Specified by:
concatin 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 newNonEmptyIterableby applying a function to all elements of thisNonEmptyIterable.- Specified by:
fmapin interfaceEnhancedIterable<A>- Specified by:
fmapin interfacecom.jnape.palatable.lambda.functor.Functor<A,EnhancedIterable<?>>- 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
NonEmptyIterable<B>
-
isEmpty
default boolean isEmpty()
Always returns false, as aNonEmptyIterableis never empty.- Specified by:
isEmptyin interfaceEnhancedIterable<A>- Returns:
- false
-
intersperse
default NonEmptyIterable<A> intersperse(A separator)
Returns a newNonEmptyIterablewith the provided separator value injected between each value of thisNonEmptyIterable.If this
NonEmptyIterablecontains only one element, it is left untouched.- Specified by:
interspersein interfaceEnhancedIterable<A>- Parameters:
separator- the separator value- Returns:
- a
NonEmptyIterable<A>
-
iterator
default java.util.Iterator<A> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<A>
-
magnetizeBy
default NonEmptyIterable<? extends NonEmptyIterable<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anIterableof contiguous groups of elements in thisNonEmptyIterablethat match a predicate pairwise.- Specified by:
magnetizeByin 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 newNonEmptyIterablewith the provided separator value injected before each value of thisNonEmptyIterable.- Specified by:
prependAllin interfaceEnhancedIterable<A>- Parameters:
separator- the separator value- Returns:
- a
NonEmptyIterable<A>
-
toFinite
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toFinite()
Converts thisNonEmptyIterableto anNonEmptyFiniteIterableif there is enough information to do so without iterating it.Note that if this method returns
nothing(), it does NOT necessarily mean thisNonEmptyIterableis infinite.- Specified by:
toFinitein interfaceEnhancedIterable<A>- Returns:
- a
Maybe<NonEmptyFiniteIterable<A>
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyIterable<A>> toNonEmpty()
Always succeeds becauseNonEmptyIterables are always non-empty.- Specified by:
toNonEmptyin interfaceEnhancedIterable<A>- Returns:
- this
NonEmptyIterablewrapped 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 thisNonEmptyIterablewith anotherNonEmptyIterableby applying a zipping function.Applies the function to the successive elements of each
Iterableuntil one of them runs out of elements.- 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
NonEmptyIterable<C>
-
zipWith
default <B,C> NonEmptyFiniteIterable<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, NonEmptyFiniteIterable<B> other)
Zips together thisNonEmptyIterablewith aNonEmptyFiniteIterableby applying a zipping function.Applies the function to the successive elements of each
Iterableuntil one of them runs out of elements.- 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>
-
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 aNonEmptyIterablecontaining 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 infiniteImmutableNonEmptyIterablethat repeatedly iterates a given element.- Type Parameters:
A- the element type- Parameters:
element- the value to repeat- Returns:
- an
ImmutableNonEmptyIterable<A>
-
-