Interface ImmutableNonEmptyVector<A>
-
- Type Parameters:
A- the element type
- All Superinterfaces:
software.kes.enhancediterables.EnhancedIterable<A>,software.kes.enhancediterables.FiniteIterable<A>,com.jnape.palatable.lambda.functor.Functor<A,software.kes.enhancediterables.EnhancedIterable<?>>,Immutable,software.kes.enhancediterables.ImmutableFiniteIterable<A>,software.kes.enhancediterables.ImmutableIterable<A>,software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>,software.kes.enhancediterables.ImmutableNonEmptyIterable<A>,ImmutableVector<A>,java.lang.Iterable<A>,software.kes.enhancediterables.NonEmptyFiniteIterable<A>,software.kes.enhancediterables.NonEmptyIterable<A>,NonEmptyVector<A>,java.util.RandomAccess,Vector<A>
public interface ImmutableNonEmptyVector<A> extends NonEmptyVector<A>, ImmutableVector<A>, software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
AVectorthat is guaranteed at compile-time to be non-empty and safe from mutation anywhere. In other words, it owns the sole reference to the underlying collection.In addition to the guarantees of
Vector,NonEmptyVector, andImmutableVector, provides the following benefits:ImmutableNonEmptyVector#fmapalways returns aImmutableNonEmptyVector.ImmutableNonEmptyVector#reversealways returns aImmutableNonEmptyVector.ImmutableNonEmptyVector#zipWithIndexalways returns aImmutableNonEmptyVector.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <A> NonEmptyVectorBuilder<A>builder(int initialCapacity, A first)Creates a newNonEmptyVectorBuilderwith an initial capacity hint.static <A> NonEmptyVectorBuilder<A>builder(A first)Creates a newNonEmptyVectorBuilder.default <B> ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>>cross(ImmutableNonEmptyVector<B> other)Returns the cartesian product of thisImmutableNonEmptyVectorwith anotherImmutableNonEmptyVector.default <B> ImmutableNonEmptyVector<B>fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)Maps a function over thisImmutableNonEmptyVector.default ImmutableVector<A>init()Returns the init of thisImmutableNonEmptyVector.default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends ImmutableNonEmptyVector<A>>magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)Returns anImmutableNonEmptyFiniteIterableof contiguous groups of elements in thisImmutableNonEmptyVectorthat match a predicate pairwise.static <A> ImmutableNonEmptyVector<A>of(A first, A... more)Creates aImmutableNonEmptyVectorwith the given elements.default ImmutableNonEmptyVector<A>reverse()Creates anImmutableNonEmptyVectorwith thisImmutableNonEmptyVector's elements in reversed order.default ImmutableVector<A>tail()Returns the tail of thisImmutableNonEmptyVector.default ImmutableNonEmptyVector<A>toImmutable()Returns anImmutableNonEmptyVectorcontaining the same elements as this one.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>>toNonEmpty()Attempts to convert thisImmutableVectorto anImmutableNonEmptyVector.default ImmutableNonEmptyVector<A>toNonEmptyOrThrow()Attempts to convert thisImmutableVectorto aImmutableNonEmptyVector.default <B,C>
ImmutableNonEmptyVector<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyVector<B> other)Zips together thisImmutableNonEmptyVectorwith anotherImmutableNonEmptyVectorby applying a zipping function.default ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,java.lang.Integer>>zipWithIndex()Zips thisImmutableNonEmptyVectorwith its indices.-
Methods inherited from interface software.kes.enhancediterables.EnhancedIterable
concat, find, toArray, toCollection, zipWith, zipWith
-
Methods inherited from interface software.kes.enhancediterables.FiniteIterable
append, concat, cross, cross, filter, foldLeft, foldRight, partition, prepend, zipWith
-
Methods inherited from interface software.kes.enhancediterables.ImmutableFiniteIterable
append, concat, cross, drop, dropWhile, filter, inits, partition, slide, span, tails, takeWhile, zipWith
-
Methods inherited from interface software.kes.enhancediterables.ImmutableIterable
concat, take, zipWith
-
Methods inherited from interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable
concat, cross, cycle, distinct, intersperse, prepend, prependAll, toFinite, zipWith
-
Methods inherited from interface software.kes.enhancediterables.ImmutableNonEmptyIterable
concat, zipWith
-
Methods inherited from interface software.kes.collectionviews.ImmutableVector
cross, drop, dropRight, dropWhile, inits, slice, slide, span, splitAt, tails, take, takeRight, takeWhile, zipWith
-
Methods inherited from interface software.kes.enhancediterables.NonEmptyFiniteIterable
concat, concat, cross, cycle, distinct, intersperse, prependAll, reduceLeft, reduceRight, toFinite, zipWith
-
-
-
-
Method Detail
-
cross
default <B> ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>> cross(ImmutableNonEmptyVector<B> other)
Returns the cartesian product of thisImmutableNonEmptyVectorwith anotherImmutableNonEmptyVector.Does not make copies of any underlying collections.
The returned
ImmutableNonEmptyVectorwill have a size ofsize()×other.size(), but will allocate no extra memory (aside from a few bytes for housekeeping).- Type Parameters:
B- the type of the otherImmutableNonEmptyVector- Parameters:
other- anImmutableNonEmptyVectorof any type- Returns:
- a
ImmutableNonEmptyVector<Tuple2<A, B>>
-
fmap
default <B> ImmutableNonEmptyVector<B> fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Maps a function over thisImmutableNonEmptyVector.Returns a new
ImmutableNonEmptyVectorof the same size (but possibly a different type).Does not make any copies of underlying collections.
This method is stack-safe, so a
ImmutableNonEmptyVectorcan be mapped as many times as the heap permits.- Specified by:
fmapin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
fmapin interfacecom.jnape.palatable.lambda.functor.Functor<A,software.kes.enhancediterables.EnhancedIterable<?>>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>- Specified by:
fmapin interfaceImmutableVector<A>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>- Specified by:
fmapin interfacesoftware.kes.enhancediterables.NonEmptyIterable<A>- Specified by:
fmapin interfaceNonEmptyVector<A>- Specified by:
fmapin interfaceVector<A>- Type Parameters:
B- The type of the elements contained in the output Vector.- Parameters:
f- a function fromAtoB. Not null. This function should be referentially transparent and not perform side-effects. It may be called zero or more times for each element.- Returns:
- an
ImmutableNonEmptyVector<B>of the same size
-
init
default ImmutableVector<A> init()
Returns the init of thisImmutableNonEmptyVector.The init of a
ImmutableNonEmptyVectoris the sameVectorwith the last element dropped. May be empty.Does not make copies of any underlying collections.
- Specified by:
initin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>- Specified by:
initin interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>- Specified by:
initin interfaceNonEmptyVector<A>- Returns:
- an
ImmutableVector<A>
-
magnetizeBy
default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends ImmutableNonEmptyVector<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anImmutableNonEmptyFiniteIterableof contiguous groups of elements in thisImmutableNonEmptyVectorthat match a predicate pairwise.- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>- Specified by:
magnetizeByin interfaceImmutableVector<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>- Specified by:
magnetizeByin interfacesoftware.kes.enhancediterables.NonEmptyIterable<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
ImmutableNonEmptyFiniteIterable<ImmutableNonEmptyVector<A>>containing the contiguous groups
-
reverse
default ImmutableNonEmptyVector<A> reverse()
Creates anImmutableNonEmptyVectorwith thisImmutableNonEmptyVector's elements in reversed order.Does not make copies of any underlying collections.
- Specified by:
reversein interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
reversein interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
reversein interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>- Specified by:
reversein interfaceImmutableVector<A>- Specified by:
reversein interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>- Specified by:
reversein interfaceNonEmptyVector<A>- Specified by:
reversein interfaceVector<A>- Returns:
- an
ImmutableNonEmptyVector<A>
-
tail
default ImmutableVector<A> tail()
Returns the tail of thisImmutableNonEmptyVector.The tail of an
ImmutableNonEmptyVectoris the sameImmutableNonEmptyVectorwith the first element dropped. May be empty.Does not make copies of any underlying collections.
- Specified by:
tailin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>- Specified by:
tailin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>- Specified by:
tailin interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>- Specified by:
tailin interfacesoftware.kes.enhancediterables.NonEmptyIterable<A>- Specified by:
tailin interfaceNonEmptyVector<A>- Returns:
- an
ImmutableVector<A>
-
toImmutable
default ImmutableNonEmptyVector<A> toImmutable()
Returns anImmutableNonEmptyVectorcontaining the same elements as this one.Since this is an
ImmutableNonEmptyVectoralready, this method simply returns itself.- Specified by:
toImmutablein interfaceImmutableVector<A>- Specified by:
toImmutablein interfaceNonEmptyVector<A>- Specified by:
toImmutablein interfaceVector<A>- Returns:
- itself
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>> toNonEmpty()
Attempts to convert thisImmutableVectorto anImmutableNonEmptyVector.Since this will always be successful for
ImmutableNonEmptyVectors, this method always returns itself wrapped in aMaybe.just(A).Does not make copies of any underlying collections.
- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>- Specified by:
toNonEmptyin interfaceImmutableVector<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.NonEmptyIterable<A>- Specified by:
toNonEmptyin interfaceNonEmptyVector<A>- Specified by:
toNonEmptyin interfaceVector<A>- Returns:
- this
ImmutableNonEmptyVectorwrapped in aMaybe.just(A)
-
toNonEmptyOrThrow
default ImmutableNonEmptyVector<A> toNonEmptyOrThrow()
Attempts to convert thisImmutableVectorto aImmutableNonEmptyVector.Since this will always be successful for
ImmutableNonEmptyVectors, this method always returns itself.Does not make copies of any underlying collections.
- Specified by:
toNonEmptyOrThrowin interfaceImmutableVector<A>- Specified by:
toNonEmptyOrThrowin interfaceNonEmptyVector<A>- Specified by:
toNonEmptyOrThrowin interfaceVector<A>- Returns:
- this
ImmutableNonEmptyVector
-
zipWith
default <B,C> ImmutableNonEmptyVector<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyVector<B> other)
Zips together thisImmutableNonEmptyVectorwith anotherImmutableNonEmptyVectorby applying a zipping function.Applies the function to the successive elements of of each
ImmutableNonEmptyVectoruntil one of them runs out of elements.Does not make copies of any underlying collections.
- Type Parameters:
B- The element type of the otherImmutableNonEmptyVectorC- 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 otherImmutableNonEmptyVector- Returns:
- A
ImmutableNonEmptyVector<C>
-
zipWithIndex
default ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,java.lang.Integer>> zipWithIndex()
Zips thisImmutableNonEmptyVectorwith its indices.Does not make copies of any underlying collections.
- Specified by:
zipWithIndexin interfaceImmutableVector<A>- Specified by:
zipWithIndexin interfaceNonEmptyVector<A>- Specified by:
zipWithIndexin interfaceVector<A>- Returns:
- a new
ImmutableNonEmptyVectorcontaining pairs consisting of all elements of thisImmutableNonEmptyVectorpaired with their index. Indices start at 0.
-
of
@SafeVarargs static <A> ImmutableNonEmptyVector<A> of(A first, A... more)
Creates aImmutableNonEmptyVectorwith the given elements.- Type Parameters:
A- the element type- Parameters:
first- the first elementmore- the remaining elements- Returns:
- an
ImmutableNonEmptyVector<A>
-
builder
static <A> NonEmptyVectorBuilder<A> builder(A first)
Creates a newNonEmptyVectorBuilder.- Type Parameters:
A- the element type- Parameters:
first- the first element- Returns:
- an empty
VectorBuilder
-
builder
static <A> NonEmptyVectorBuilder<A> builder(int initialCapacity, A first)
Creates a newNonEmptyVectorBuilderwith an initial capacity hint.- Type Parameters:
A- the element type- Parameters:
initialCapacity- an initial capacity hint. Must be >= 0.first- the first element- Returns:
- an empty
VectorBuilder
-
-