Interface ImmutableVector<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>,java.lang.Iterable<A>,java.util.RandomAccess,Vector<A>
- All Known Subinterfaces:
 ImmutableNonEmptyVector<A>
public interface ImmutableVector<A> extends Vector<A>, software.kes.enhancediterables.ImmutableFiniteIterable<A>, Immutable
AVectorthat is guaranteed at compile-time to be safe from mutation anywhere. In other words, it owns the sole reference to the underlying collection.In addition to guarantees of
Vector, provides the following benefits :fmap(com.jnape.palatable.lambda.functions.Fn1<? super A, ? extends B>)always returns aImmutableVector.take(int)always returns aImmutableVector.drop(int)always returns aImmutableVector.slice(int, int)always returns aImmutableVector.reverse()always returns aImmutableVector.zipWithIndex()always returns aImmutableVector.toImmutable()always returns itself.
 
- 
- 
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <A> VectorBuilder<A>builder()Creates a newVectorBuilder.static <A> VectorBuilder<A>builder(int initialCapacity)Creates a newVectorBuilderwith an initial capacity hint.default <B> ImmutableVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>>cross(ImmutableVector<B> other)Returns the cartesian product of thisImmutableVectorwith anotherImmutableVector.default ImmutableVector<A>drop(int count)Returns a newImmutableVectorthat drops the firstcountelements of thisImmutableVector.default ImmutableVector<A>dropRight(int count)Returns a newImmutableVectorthat drops all except the lastcountelements of thisImmutableVector.default ImmutableVector<A>dropWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)Returns a newImmutableVectorthat drops longest prefix of elements of thisImmutableVectorthat satisfy a predicate.default <B> ImmutableVector<B>fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)Maps a function over thisImmutableVector.default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends ImmutableVector<A>>inits()Returns aNonEmptyIterablecontaining the inits of thisImmutableVector.default software.kes.enhancediterables.ImmutableFiniteIterable<? extends ImmutableNonEmptyVector<A>>magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)Returns anImmutableFiniteIterableof contiguous groups of elements in thisImmutableVectorthat match a predicate pairwise.default ImmutableVector<A>reverse()Creates anImmutableVectorwith thisImmutableVector's elements in reversed order.default ImmutableVector<A>slice(int startIndex, int endIndexExclusive)Creates a slice of thisImmutableVector.default software.kes.enhancediterables.ImmutableFiniteIterable<? extends ImmutableNonEmptyVector<A>>slide(int k)"Slides" a window ofkelements across theImmutableVectorby one element at a time.default com.jnape.palatable.lambda.adt.hlist.Tuple2<ImmutableVector<A>,ImmutableVector<A>>span(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)Splits thisImmutableVectorinto a prefix/suffix pair according to a predicate.default com.jnape.palatable.lambda.adt.hlist.Tuple2<ImmutableVector<A>,ImmutableVector<A>>splitAt(int index)Splits thisImmutableVectorinto two at a given position.default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<ImmutableVector<A>>tails()Returns aNonEmptyIterablecontaining the tails of thisImmutableVector.default ImmutableVector<A>take(int count)Returns a newImmutableVectorcontaining at most the firstcountelements of thisImmutableVector.default ImmutableVector<A>takeRight(int count)Returns a newImmutableVectorcontaining at most the lastcountelements of thisImmutableVector.default ImmutableVector<A>takeWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)Returns a newImmutableVectorcontaining the longest prefix of elements thisImmutableVectorthat satisfy a predicate.default ImmutableVector<A>toImmutable()Returns anImmutableVectorcontaining 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 anImmutableNonEmptyVector.default <B,C>
ImmutableVector<C>zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableVector<B> other)Zips together thisImmutableVectorwith anotherImmutableVectorby applying a zipping function.default ImmutableVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,java.lang.Integer>>zipWithIndex()Zips thisImmutableVectorwith its indices.- 
Methods inherited from interface software.kes.enhancediterables.EnhancedIterable
concat, concat, find, toArray, toCollection, zipWith, zipWith 
- 
Methods inherited from interface software.kes.enhancediterables.FiniteIterable
append, concat, concat, concat, cross, cross, filter, foldLeft, foldRight, intersperse, partition, prepend, prependAll, toFinite, zipWith 
- 
Methods inherited from interface software.kes.enhancediterables.ImmutableFiniteIterable
append, concat, concat, cross, cycle, distinct, filter, intersperse, partition, prepend, prependAll, toFinite, zipWith 
 - 
 
 - 
 
- 
- 
Method Detail
- 
cross
default <B> ImmutableVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,B>> cross(ImmutableVector<B> other)
Returns the cartesian product of thisImmutableVectorwith anotherImmutableVector.Does not make copies of any underlying collections.
The returned
ImmutableVectorwill 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 otherImmutableVector- Parameters:
 other- anImmutableVectorof any type- Returns:
 - a 
ImmutableVector<Tuple2<A, B>> 
 
- 
drop
default ImmutableVector<A> drop(int count)
Returns a newImmutableVectorthat drops the firstcountelements of thisImmutableVector.Does not make copies of any underlying collections.
Use caution when taking a small slice of a huge
ImmutableVectorthat you no longer need. The smaller slice will hold onto a reference of the larger one, and will prevent it from being GC'ed.- Specified by:
 dropin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 dropin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
 dropin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
 dropin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
 dropin interfaceVector<A>- Parameters:
 count- the number of elements to drop from thisImmutableVector. Must be >= 0. May exceed size of thisImmutableVector, in which case, the result will be an emptyImmutableVector.- Returns:
 - an 
ImmutableVector<A> 
 
- 
dropRight
default ImmutableVector<A> dropRight(int count)
Returns a newImmutableVectorthat drops all except the lastcountelements of thisImmutableVector.Does not make copies of any underlying collections.
Use caution when taking a small slice of a huge
Vectorthat you no longer need. The smaller slice will hold onto a reference of the larger one, and will prevent it from being GC'ed. 
- 
dropWhile
default ImmutableVector<A> dropWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableVectorthat drops longest prefix of elements of thisImmutableVectorthat satisfy a predicate.Does not make copies of any underlying collections.
- Specified by:
 dropWhilein interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 dropWhilein interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
 dropWhilein interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
 dropWhilein interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Parameters:
 predicate- a predicate; 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 
ImmutableVector<A> 
 
- 
fmap
default <B> ImmutableVector<B> fmap(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends B> f)
Maps a function over thisImmutableVector.Returns a new
ImmutableVectorof the same size (but possibly a different type).Does not make any copies of underlying collections.
This method is stack-safe, so a
ImmutableVectorcan 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 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 
ImmutableVector<B>of the same size 
 
- 
inits
default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends ImmutableVector<A>> inits()
Returns aNonEmptyIterablecontaining the inits of thisImmutableVector.The first value will be this
ImmutableVectorand the final one will be an emptyVector, with the intervening values the results of successive applications ofinit. 
- 
magnetizeBy
default software.kes.enhancediterables.ImmutableFiniteIterable<? extends ImmutableNonEmptyVector<A>> magnetizeBy(com.jnape.palatable.lambda.functions.Fn2<A,A,java.lang.Boolean> predicate)
Returns anImmutableFiniteIterableof contiguous groups of elements in thisImmutableVectorthat 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>- 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 
ImmutableFiniteIterable<ImmutableNonEmptyVector<A>>containing the contiguous groups 
 
- 
reverse
default ImmutableVector<A> reverse()
Creates anImmutableVectorwith thisImmutableVector's elements in reversed order.Does not make copies of any underlying collections.
 
- 
slice
default ImmutableVector<A> slice(int startIndex, int endIndexExclusive)
Creates a slice of thisImmutableVector.Does not make copies of any underlying collections.
Use caution when taking a small slice of a huge
ImmutableVectorthat you no longer need. The smaller slice will hold onto a reference of the larger one, and will prevent it from being GC'ed. To avoid this situation, useVector.copySliceFrom(int, int, java.lang.Iterable<A>)instead.- Specified by:
 slicein interfaceVector<A>- Parameters:
 startIndex- the index of the element to begin the slice. Must be >= 0. May exceed the size of thisImmutableVector, in which case an emptyImmutableVectorwill be returned.endIndexExclusive- the end index (exclusive) of the slice. Must be >=startIndex. May exceed the size of thisImmutableVector, in which case the slice will contain as many elements as available.- Returns:
 - an 
ImmutableVector<A> 
 
- 
slide
default software.kes.enhancediterables.ImmutableFiniteIterable<? extends ImmutableNonEmptyVector<A>> slide(int k)
"Slides" a window ofkelements across theImmutableVectorby one element at a time.Example:
Vector.of(1, 2, 3, 4, 5).slide(2); // [[1, 2], [2, 3], [3, 4], [4, 5]]- Specified by:
 slidein interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 slidein interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
 slidein interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
 slidein interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
 slidein interfaceVector<A>- Parameters:
 k- the number of elements in the sliding window. Must be >= 1.- Returns:
 - an 
FiniteIterable<ImmutableNonEmptyVector<A>> 
 
- 
span
default com.jnape.palatable.lambda.adt.hlist.Tuple2<ImmutableVector<A>,ImmutableVector<A>> span(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Splits thisImmutableVectorinto a prefix/suffix pair according to a predicate.Does not make copies of any underlying collections.
Note that
vector.span(p)is equivalent to, but possibly more efficient thantuple(vector.takeWhile(p), vector.dropWhile(p))- Specified by:
 spanin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 spanin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
 spanin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
 spanin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Parameters:
 predicate- a predicate; 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:
 - a 
Tuple2contains ofImmutableVectors, one of which containing the firstindexelements that satisfied the predicate, the second containing the other elements. 
 
- 
splitAt
default com.jnape.palatable.lambda.adt.hlist.Tuple2<ImmutableVector<A>,ImmutableVector<A>> splitAt(int index)
Splits thisImmutableVectorinto two at a given position.Does not make copies of any underlying collections.
Note that
vector.splitAt(n)is equivalent to, but possibly more efficient thantuple(vector.take(n), vector.drop(n)) 
- 
tails
default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<ImmutableVector<A>> tails()
Returns aNonEmptyIterablecontaining the tails of thisImmutableVector.The first value will be this
ImmutableVectorand the final one will be an emptyImmutableVector, with the intervening values the results of successive applications oftail.- Specified by:
 tailsin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 tailsin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
 tailsin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
 tailsin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
 tailsin interfaceVector<A>- Returns:
 - a 
NonEmptyIterableover all the tails of thisImmutableVector 
 
- 
take
default ImmutableVector<A> take(int count)
Returns a newImmutableVectorcontaining at most the firstcountelements of thisImmutableVector.Does not make copies of any underlying collections.
Use caution when taking a small slice of a huge
ImmutableVectorthat you no longer need. The smaller slice will hold onto a reference of the larger one, and will prevent it from being GC'ed. To avoid this situation, useVector.copyFrom(int, Iterable)instead.- Specified by:
 takein interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 takein interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
 takein interfaceVector<A>- Parameters:
 count- the maximum number of elements to take from thisImmutableVector. Must be >= 0. May exceed size of thisImmutableVector.- Returns:
 - an 
ImmutableVector<A> 
 
- 
takeRight
default ImmutableVector<A> takeRight(int count)
Returns a newImmutableVectorcontaining at most the lastcountelements of thisImmutableVector.Does not make copies of any underlying collections.
Use caution when taking a small slice of a huge
ImmutableVectorthat you no longer need. The smaller slice will hold onto a reference of the larger one, and will prevent it from being GC'ed. To avoid this situation, useVector.copyFrom(int, Iterable)instead. 
- 
takeWhile
default ImmutableVector<A> takeWhile(com.jnape.palatable.lambda.functions.Fn1<? super A,? extends java.lang.Boolean> predicate)
Returns a newImmutableVectorcontaining the longest prefix of elements thisImmutableVectorthat satisfy a predicate.Does not make copies of any underlying collections.
- Specified by:
 takeWhilein interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
 takeWhilein interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
 takeWhilein interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
 takeWhilein interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Parameters:
 predicate- a predicate; 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 
ImmutableVector<A> 
 
- 
toImmutable
default ImmutableVector<A> toImmutable()
Returns anImmutableVectorcontaining the same elements as this one.Since this is an
ImmutableVectoralready, this method simply returns itself.- Specified by:
 toImmutablein interfaceVector<A>- Returns:
 - itself
 
 
- 
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>> toNonEmpty()
Attempts to convert thisImmutableVectorto anImmutableNonEmptyVector.If successful, returns a
ImmutableNonEmptyVectorcontaining the same elements as this one, wrapped in aMaybe.just(A).If this
ImmutableVectoris empty, returnsMaybe.nothing().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 interfaceVector<A>- Returns:
 - a 
Maybe<ImmutableNonEmptyVector<A>> 
 
- 
toNonEmptyOrThrow
default ImmutableNonEmptyVector<A> toNonEmptyOrThrow()
Attempts to convert thisImmutableVectorto anImmutableNonEmptyVector.If successful, returns a
ImmutableNonEmptyVectorcontaining the same elements as this one. Use this if you are confident that thisImmutableVectoris not empty.If this
ImmutableVectoris empty, throws anIllegalArgumentException.Does not make copies of any underlying collections.
- Specified by:
 toNonEmptyOrThrowin interfaceVector<A>- Returns:
 - an 
ImmutableNonEmptyVector<A> - Throws:
 java.lang.IllegalArgumentException- if thisImmutableVectoris empty
 
- 
zipWith
default <B,C> ImmutableVector<C> zipWith(com.jnape.palatable.lambda.functions.Fn2<A,B,C> fn, ImmutableVector<B> other)
Zips together thisImmutableVectorwith anotherImmutableVectorby applying a zipping function.Applies the function to the successive elements of of each
ImmutableVectoruntil one of them runs out of elements.Does not make copies of any underlying collections.
- Type Parameters:
 B- The element type of the otherImmutableVectorC- 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 otherImmutableVector- Returns:
 - An 
ImmutableVector<C> 
 
- 
zipWithIndex
default ImmutableVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,java.lang.Integer>> zipWithIndex()
Zips thisImmutableVectorwith its indices.Does not make copies of any underlying collections.
- Specified by:
 zipWithIndexin interfaceVector<A>- Returns:
 - a new 
ImmutableVectorcontaining pairs consisting of all elements of thisImmutableVectorpaired with their index. Indices start at 0. 
 
- 
builder
static <A> VectorBuilder<A> builder()
Creates a newVectorBuilder.- Type Parameters:
 A- the element type- Returns:
 - an empty 
VectorBuilder 
 
- 
builder
static <A> VectorBuilder<A> builder(int initialCapacity)
Creates a newVectorBuilderwith an initial capacity hint.- Type Parameters:
 A- the element type- Parameters:
 initialCapacity- an initial capacity hint. Must be >= 0.- Returns:
 - an empty 
VectorBuilder 
 
 - 
 
 -