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>
AVector
that 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#fmap
always returns aImmutableNonEmptyVector
.ImmutableNonEmptyVector#reverse
always returns aImmutableNonEmptyVector
.ImmutableNonEmptyVector#zipWithIndex
always 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 newNonEmptyVectorBuilder
with 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 thisImmutableNonEmptyVector
with 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 anImmutableNonEmptyFiniteIterable
of contiguous groups of elements in thisImmutableNonEmptyVector
that match a predicate pairwise.static <A> ImmutableNonEmptyVector<A>
of(A first, A... more)
Creates aImmutableNonEmptyVector
with the given elements.default ImmutableNonEmptyVector<A>
reverse()
Creates anImmutableNonEmptyVector
with thisImmutableNonEmptyVector
's elements in reversed order.default ImmutableVector<A>
tail()
Returns the tail of thisImmutableNonEmptyVector
.default ImmutableNonEmptyVector<A>
toImmutable()
Returns anImmutableNonEmptyVector
containing the same elements as this one.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>>
toNonEmpty()
Attempts to convert thisImmutableVector
to anImmutableNonEmptyVector
.default ImmutableNonEmptyVector<A>
toNonEmptyOrThrow()
Attempts to convert thisImmutableVector
to aImmutableNonEmptyVector
.default <B,C>
ImmutableNonEmptyVector<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableNonEmptyVector<B> other)
Zips together thisImmutableNonEmptyVector
with anotherImmutableNonEmptyVector
by applying a zipping function.default ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,java.lang.Integer>>
zipWithIndex()
Zips thisImmutableNonEmptyVector
with 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 thisImmutableNonEmptyVector
with anotherImmutableNonEmptyVector
.Does not make copies of any underlying collections.
The returned
ImmutableNonEmptyVector
will 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
- anImmutableNonEmptyVector
of 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
ImmutableNonEmptyVector
of the same size (but possibly a different type).Does not make any copies of underlying collections.
This method is stack-safe, so a
ImmutableNonEmptyVector
can be mapped as many times as the heap permits.- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.EnhancedIterable<A>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.FiniteIterable<A>
- Specified by:
fmap
in interfacecom.jnape.palatable.lambda.functor.Functor<A,software.kes.enhancediterables.EnhancedIterable<?>>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.ImmutableIterable<A>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>
- Specified by:
fmap
in interfaceImmutableVector<A>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>
- Specified by:
fmap
in interfacesoftware.kes.enhancediterables.NonEmptyIterable<A>
- Specified by:
fmap
in interfaceNonEmptyVector<A>
- Specified by:
fmap
in interfaceVector<A>
- Type Parameters:
B
- The type of the elements contained in the output Vector.- Parameters:
f
- a function fromA
toB
. 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
ImmutableNonEmptyVector
is the sameVector
with the last element dropped. May be empty.Does not make copies of any underlying collections.
- Specified by:
init
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
- Specified by:
init
in interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>
- Specified by:
init
in 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 anImmutableNonEmptyFiniteIterable
of contiguous groups of elements in thisImmutableNonEmptyVector
that match a predicate pairwise.- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.EnhancedIterable<A>
- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.FiniteIterable<A>
- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>
- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.ImmutableIterable<A>
- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>
- Specified by:
magnetizeBy
in interfaceImmutableVector<A>
- Specified by:
magnetizeBy
in interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>
- Specified by:
magnetizeBy
in 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 anImmutableNonEmptyVector
with thisImmutableNonEmptyVector
's elements in reversed order.Does not make copies of any underlying collections.
- Specified by:
reverse
in interfacesoftware.kes.enhancediterables.FiniteIterable<A>
- Specified by:
reverse
in interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>
- Specified by:
reverse
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
- Specified by:
reverse
in interfaceImmutableVector<A>
- Specified by:
reverse
in interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>
- Specified by:
reverse
in interfaceNonEmptyVector<A>
- Specified by:
reverse
in interfaceVector<A>
- Returns:
- an
ImmutableNonEmptyVector<A>
-
tail
default ImmutableVector<A> tail()
Returns the tail of thisImmutableNonEmptyVector
.The tail of an
ImmutableNonEmptyVector
is the sameImmutableNonEmptyVector
with the first element dropped. May be empty.Does not make copies of any underlying collections.
- Specified by:
tail
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
- Specified by:
tail
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>
- Specified by:
tail
in interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>
- Specified by:
tail
in interfacesoftware.kes.enhancediterables.NonEmptyIterable<A>
- Specified by:
tail
in interfaceNonEmptyVector<A>
- Returns:
- an
ImmutableVector<A>
-
toImmutable
default ImmutableNonEmptyVector<A> toImmutable()
Returns anImmutableNonEmptyVector
containing the same elements as this one.Since this is an
ImmutableNonEmptyVector
already, this method simply returns itself.- Specified by:
toImmutable
in interfaceImmutableVector<A>
- Specified by:
toImmutable
in interfaceNonEmptyVector<A>
- Specified by:
toImmutable
in interfaceVector<A>
- Returns:
- itself
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>> toNonEmpty()
Attempts to convert thisImmutableVector
to anImmutableNonEmptyVector
.Since this will always be successful for
ImmutableNonEmptyVector
s, this method always returns itself wrapped in aMaybe.just(A)
.Does not make copies of any underlying collections.
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.EnhancedIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.FiniteIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.ImmutableIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.ImmutableNonEmptyIterable<A>
- Specified by:
toNonEmpty
in interfaceImmutableVector<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.NonEmptyFiniteIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.NonEmptyIterable<A>
- Specified by:
toNonEmpty
in interfaceNonEmptyVector<A>
- Specified by:
toNonEmpty
in interfaceVector<A>
- Returns:
- this
ImmutableNonEmptyVector
wrapped in aMaybe.just(A)
-
toNonEmptyOrThrow
default ImmutableNonEmptyVector<A> toNonEmptyOrThrow()
Attempts to convert thisImmutableVector
to aImmutableNonEmptyVector
.Since this will always be successful for
ImmutableNonEmptyVector
s, this method always returns itself.Does not make copies of any underlying collections.
- Specified by:
toNonEmptyOrThrow
in interfaceImmutableVector<A>
- Specified by:
toNonEmptyOrThrow
in interfaceNonEmptyVector<A>
- Specified by:
toNonEmptyOrThrow
in 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 thisImmutableNonEmptyVector
with anotherImmutableNonEmptyVector
by applying a zipping function.Applies the function to the successive elements of of each
ImmutableNonEmptyVector
until one of them runs out of elements.Does not make copies of any underlying collections.
- Type Parameters:
B
- The element type of the otherImmutableNonEmptyVector
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 otherImmutableNonEmptyVector
- Returns:
- A
ImmutableNonEmptyVector<C>
-
zipWithIndex
default ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,java.lang.Integer>> zipWithIndex()
Zips thisImmutableNonEmptyVector
with its indices.Does not make copies of any underlying collections.
- Specified by:
zipWithIndex
in interfaceImmutableVector<A>
- Specified by:
zipWithIndex
in interfaceNonEmptyVector<A>
- Specified by:
zipWithIndex
in interfaceVector<A>
- Returns:
- a new
ImmutableNonEmptyVector
containing pairs consisting of all elements of thisImmutableNonEmptyVector
paired with their index. Indices start at 0.
-
of
@SafeVarargs static <A> ImmutableNonEmptyVector<A> of(A first, A... more)
Creates aImmutableNonEmptyVector
with 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 newNonEmptyVectorBuilder
with 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
-
-