Interface Vector<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<?>>, java.lang.Iterable<A>, java.util.RandomAccess
    All Known Subinterfaces:
    ImmutableNonEmptyVector<A>, ImmutableVector<A>, NonEmptyVector<A>

    public interface Vector<A>
    extends software.kes.enhancediterables.FiniteIterable<A>, java.util.RandomAccess
    A finite, ordered view of a collection.

    A Vector guarantees the following:

    • A size() method that executes in O(1)*.
    • A get(int) method that retrieves an element by index in O(1)*.
    • An isEmpty() method that executes in O(1)*.
    • Iteration will always terminate.
    • Protected from mutation by the bearer.
    • The bearer cannot gain access to a reference to the underlying collection.

    Additionally, the ability to transform the Vector to new Vectors, without affecting or copying the underlying collection, is provided through the following methods:

    While Vector does implement Iterable, it does not implement Collection. If you need to convert the Vector to a java.util.Collection, you will need to make a copy. Consider using Lambda's toCollection function to accomplish this.

    *The claim of O(1) means that the number of elements in the Vector has no bearing on performance. However, the number of transformations applied to the Vector, such as mapping and slicing, will. Technically, the complexity is O(k) where k is the number of transformations applied.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static <A> VectorBuilder<A> builder()
      Creates a new VectorBuilder.
      static <A> VectorBuilder<A> builder​(int initialCapacity)
      Creates a new VectorBuilder with an initial capacity hint.
      static <A> ImmutableVector<A> copyFrom​(int maxCount, A[] source)
      Returns a new ImmutableVector that is copied from an array.
      static <A> ImmutableVector<A> copyFrom​(int maxCount, java.lang.Iterable<A> source)
      Creates an ImmutableVector that is copied from any Iterable, but consuming a maximum number of elements.
      static <A> ImmutableVector<A> copyFrom​(A[] source)
      Creates an ImmutableVector that is copied from an array.
      static <A> ImmutableVector<A> copyFrom​(java.lang.Iterable<A> source)
      Creates an ImmutableVector that is copied from any Iterable.
      static <A> ImmutableVector<A> copySliceFrom​(int startIndex, int endIndexExclusive, java.lang.Iterable<A> source)
      Creates an ImmutableVector by copying a slice from an Iterable.
      default <B> Vector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​B>> cross​(Vector<B> other)
      Returns the cartesian product of this Vector with another Vector.
      default Vector<A> drop​(int count)
      Returns a new Vector that drops the first count elements of this Vector.
      default Vector<A> dropRight​(int count)
      Returns a new Vector that drops all except the last count elements of this Vector.
      static <A> ImmutableVector<A> empty()
      Returns an empty ImmutableVector.
      static <A> ImmutableVector<A> fill​(int size, A value)
      Creates an ImmutableVector that repeats the same element size times.
      default com.jnape.palatable.lambda.adt.Maybe<java.lang.Integer> findIndex​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends java.lang.Boolean> predicate)
      Finds the first element of this Vector that satisfies a predicate, if any, and returns its index.
      default <B> Vector<B> fmap​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends B> f)
      Maps a function over this Vector.
      default com.jnape.palatable.lambda.adt.Maybe<A> get​(int index)
      Gets an element from this Vector at an index.
      default ImmutableVector<java.lang.Integer> indices()
      Returns an ImmutableVector<Integer> that contains all the indices of this Vector.
      default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends Vector<A>> inits()
      Returns a NonEmptyIterable containing the inits of this Vector.
      default boolean isEmpty()
      Tests whether this Vector is empty.
      default java.util.Iterator<A> iterator()
      Returns an iterator over this Vector's elements.
      static <A> ImmutableVector<A> lazyFill​(int size, com.jnape.palatable.lambda.functions.Fn1<java.lang.Integer,​A> valueSupplier)
      Creates an ImmutableVector where elements are lazily evaluated.
      static <A> ImmutableNonEmptyVector<A> of​(A first, A... more)
      Creates a ImmutableNonEmptyVector with the given elements.
      static ImmutableVector<java.lang.Integer> range​(int size)
      Creates an ImmutableVector<Integer> containing elements 0..size - 1.
      default Vector<A> reverse()
      Creates a Vector with this Vector's elements in reversed order.
      int size()
      Returns the size of this Vector.
      default Vector<A> slice​(int startIndex, int endIndexExclusive)
      Creates a slice of this Vector.
      default software.kes.enhancediterables.FiniteIterable<? extends NonEmptyVector<A>> slide​(int k)
      "Slides" a window of k elements across the Vector by one element at a time.
      default com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends Vector<A>,​? extends Vector<A>> splitAt​(int index)
      Splits this Vector into two at a given position.
      default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends Vector<A>> tails()
      Returns a NonEmptyIterable containing the tails of this Vector.
      default Vector<A> take​(int count)
      Returns a new Vector containing at most the first count elements of this Vector.
      default Vector<A> takeRight​(int count)
      Returns a new Vector containing at most the last count elements of this Vector.
      default ImmutableVector<A> toImmutable()
      Converts this Vector to an ImmutableVector.
      default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyVector<A>> toNonEmpty()
      Attempts to convert this Vector to a NonEmptyVector.
      default NonEmptyVector<A> toNonEmptyOrThrow()
      Attempts to convert this Vector to a NonEmptyVector.
      A unsafeGet​(int index)
      Gets an element from this Vector at an index.
      static <A> Vector<A> wrap​(A[] underlying)
      Creates a Vector that wraps an array.
      static <A> Vector<A> wrap​(java.util.List<A> underlying)
      Creates a Vector that wraps a java.util.List.
      default <B,​C>
      Vector<C>
      zipWith​(com.jnape.palatable.lambda.functions.Fn2<A,​B,​C> fn, Vector<B> other)
      Zips together this Vector with another Vector by applying a zipping function.
      default Vector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​java.lang.Integer>> zipWithIndex()
      Zips this Vector with 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, cycle, distinct, dropWhile, filter, foldLeft, foldRight, intersperse, magnetizeBy, partition, prepend, prependAll, span, takeWhile, toFinite, zipWith
      • Methods inherited from interface com.jnape.palatable.lambda.functor.Functor

        coerce
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • size

        int size()
        Returns the size of this Vector.

        Executes in O(1).

        Specified by:
        size in interface software.kes.enhancediterables.FiniteIterable<A>
        Returns:
        the number of elements in this Vector
      • unsafeGet

        A unsafeGet​(int index)
        Gets an element from this Vector at an index.

        Executes in O(1).

        Parameters:
        index - the index of the element to retrieve. Must be between 0 and size() - 1, otherwise will throw an IndexOutOfBoundsException
        Returns:
        the element at index. May be null, if the underlying data contains a null at that index.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is less than 0 or greater than or equal to size()
      • cross

        default <B> Vector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​B>> cross​(Vector<B> other)
        Returns the cartesian product of this Vector with another Vector.

        Does not make copies of any underlying collections.

        The returned Vector will have a size of size() × other.size(), but will allocate no extra memory (aside from a few bytes for housekeeping).

        Type Parameters:
        B - the type of the other Vector
        Parameters:
        other - a Vector of any type
        Returns:
        a Vector<Tuple2<A, B>>
      • drop

        default Vector<A> drop​(int count)
        Returns a new Vector that drops the first count elements of this Vector.

        Does not make copies of any underlying collections.

        Use caution when taking a small slice of a huge Vector that 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:
        drop in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        drop in interface software.kes.enhancediterables.FiniteIterable<A>
        Parameters:
        count - the number of elements to drop from this Vector. Must be >= 0. May exceed size of this Vector, in which case, the result will be an empty Vector.
        Returns:
        a Vector<A>
      • dropRight

        default Vector<A> dropRight​(int count)
        Returns a new Vector that drops all except the last count elements of this Vector.

        Does not make copies of any underlying collections.

        Use caution when taking a small slice of a huge Vector that you no longer need. The smaller slice will hold onto a reference of the larger one, and will prevent it from being GC'ed.

        Parameters:
        count - the number of elements to drop from the end of this Vector. Must be >= 0. May exceed size of this Vector, in which case, the result will be an empty Vector.
        Returns:
        a Vector<A>
      • findIndex

        default com.jnape.palatable.lambda.adt.Maybe<java.lang.Integer> findIndex​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends java.lang.Boolean> predicate)
        Finds the first element of this Vector that satisfies a predicate, if any, and returns its index.
        Parameters:
        predicate - a predicate; not null
        Returns:
        an index wrapped in a Maybe.just(A) if a matching element is found; Maybe.nothing() otherwise.
      • fmap

        default <B> Vector<B> fmap​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends B> f)
        Maps a function over this Vector.

        Returns a new Vector of the same size (but possibly a different type).

        Does not make any copies of underlying collections.

        This method is stack-safe, so a Vector can be mapped as many times as the heap permits.

        Specified by:
        fmap in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        fmap in interface software.kes.enhancediterables.FiniteIterable<A>
        Specified by:
        fmap in interface com.jnape.palatable.lambda.functor.Functor<A,​software.kes.enhancediterables.EnhancedIterable<?>>
        Type Parameters:
        B - The type of the elements contained in the output Vector.
        Parameters:
        f - a function from A to B. 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 Vector<B> of the same size
      • get

        default com.jnape.palatable.lambda.adt.Maybe<A> get​(int index)
        Gets an element from this Vector at an index.

        Executes in O(1). Will never return null.

        Parameters:
        index - the index of the element to retrieve
        Returns:
        an element wrapped in a Maybe.just(A) if the index is in range and the element is not null. Maybe.nothing() otherwise.
      • indices

        default ImmutableVector<java.lang.Integer> indices()
        Returns an ImmutableVector<Integer> that contains all the indices of this Vector.
        Returns:
        an ImmutableVector<Integer>
      • inits

        default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends Vector<A>> inits()
        Returns a NonEmptyIterable containing the inits of this Vector.

        The first value will be this Vector and the final one will be an empty Vector, with the intervening values the results of successive applications of init.

        Specified by:
        inits in interface software.kes.enhancediterables.FiniteIterable<A>
        Returns:
        a NonEmptyIterable over all the inits of this Vector
      • isEmpty

        default boolean isEmpty()
        Tests whether this Vector is empty.

        Executes in O(1).

        Specified by:
        isEmpty in interface software.kes.enhancediterables.EnhancedIterable<A>
        Returns:
        true if this Vector is empty, false otherwise.
      • iterator

        default java.util.Iterator<A> iterator()
        Returns an iterator over this Vector's elements.
        Specified by:
        iterator in interface java.lang.Iterable<A>
        Returns:
        an Iterator
      • reverse

        default Vector<A> reverse()
        Creates a Vector with this Vector's elements in reversed order.

        Does not make copies of any underlying collections.

        Specified by:
        reverse in interface software.kes.enhancediterables.FiniteIterable<A>
        Returns:
        a Vector<A>
      • slice

        default Vector<A> slice​(int startIndex,
                                int endIndexExclusive)
        Creates a slice of this Vector.

        Does not make copies of any underlying collections.

        Use caution when taking a small slice of a huge Vector that 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, use copySliceFrom(int, int, java.lang.Iterable<A>) instead.

        Parameters:
        startIndex - the index of the element to begin the slice. Must be >= 0. May exceed the size of this Vector, in which case an empty Vector will be returned.
        endIndexExclusive - the end index (exclusive) of the slice. Must be >= startIndex. May exceed the size of this Vector, in which case the slice will contain as many elements as available.
        Returns:
        a Vector<A>
      • slide

        default software.kes.enhancediterables.FiniteIterable<? extends NonEmptyVector<A>> slide​(int k)
        "Slides" a window of k elements across the Vector by 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:
        slide in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        slide in interface software.kes.enhancediterables.FiniteIterable<A>
        Parameters:
        k - the number of elements in the sliding window. Must be >= 1.
        Returns:
        an FiniteIterable<NonEmptyVector<A>>
      • splitAt

        default com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends Vector<A>,​? extends Vector<A>> splitAt​(int index)
        Splits this Vector into 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 than tuple(vector.take(n), vector.drop(n))

        Parameters:
        index - the position at which to split. Must be >= 0;
        Returns:
        a Tuple2 contains of Vectors, one of which containing the first index elements, the second containing the other elements.
      • tails

        default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends Vector<A>> tails()
        Returns a NonEmptyIterable containing the tails of this Vector.

        The first value will be this Vector and the final one will be an empty Vector, with the intervening values the results of successive applications of tail.

        Specified by:
        tails in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        tails in interface software.kes.enhancediterables.FiniteIterable<A>
        Returns:
        a NonEmptyIterable over all the tails of this Vector
      • take

        default Vector<A> take​(int count)
        Returns a new Vector containing at most the first count elements of this Vector.

        Does not make copies of any underlying collections.

        Use caution when taking a small slice of a huge Vector that 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, use copyFrom(int, Iterable) instead.

        Specified by:
        take in interface software.kes.enhancediterables.EnhancedIterable<A>
        Parameters:
        count - the maximum number of elements to take from this Vector. Must be >= 0. May exceed size of this Vector.
        Returns:
        a Vector<A>
      • takeRight

        default Vector<A> takeRight​(int count)
        Returns a new Vector containing at most the last count elements of this Vector.

        Does not make copies of any underlying collections.

        Use caution when taking a small slice of a huge Vector that 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, use copyFrom(int, Iterable) instead.

        Parameters:
        count - the maximum number of elements to take from this Vector. Must be >= 0. May exceed size of this Vector.
        Returns:
        a Vector<A>
      • toImmutable

        default ImmutableVector<A> toImmutable()
        Converts this Vector to an ImmutableVector.

        This method will make a copy of the underlying data structure if necessary to guarantee immutability.

        If this Vector is already an ImmutableVector, no copies are made and this method is a no-op.

        Returns:
        an ImmutableVector of the same type and containing the same elements
      • toNonEmpty

        default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyVector<A>> toNonEmpty()
        Attempts to convert this Vector to a NonEmptyVector.

        If successful, returns a NonEmptyVector containing the same elements as this one, wrapped in a Maybe.just(A).

        If this Vector is empty, returns Maybe.nothing().

        Does not make copies of any underlying collections.

        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.FiniteIterable<A>
        Returns:
        a Maybe<NonEmptyVector<A>>
      • toNonEmptyOrThrow

        default NonEmptyVector<A> toNonEmptyOrThrow()
        Attempts to convert this Vector to a NonEmptyVector.

        If successful, returns a NonEmptyVector containing the same elements as this one. Use this if you are confident that this Vector is not empty.

        If this Vector is empty, throws an IllegalArgumentException.

        Does not make copies of any underlying collections.

        Returns:
        a NonEmptyVector<A>
        Throws:
        java.lang.IllegalArgumentException - if this Vector is empty
      • zipWith

        default <B,​C> Vector<C> zipWith​(com.jnape.palatable.lambda.functions.Fn2<A,​B,​C> fn,
                                              Vector<B> other)
        Zips together this Vector with another Vector by applying a zipping function.

        Applies the function to the successive elements of of each Vector until one of them runs out of elements.

        Does not make copies of any underlying collections.

        Type Parameters:
        B - The element type of the other Vector
        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 other Vector
        Returns:
        A Vector<C>
      • zipWithIndex

        default Vector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​java.lang.Integer>> zipWithIndex()
        Zips this Vector with its indices.

        Does not make copies of any underlying collections.

        Returns:
        a new Vector containing pairs consisting of all elements of this Vector paired with their index. Indices start at 0.
      • empty

        static <A> ImmutableVector<A> empty()
        Returns an empty ImmutableVector.
        Type Parameters:
        A - the element type
        Returns:
        an empty ImmutableVector<A>
      • of

        @SafeVarargs
        static <A> ImmutableNonEmptyVector<A> of​(A first,
                                                 A... more)
        Creates a ImmutableNonEmptyVector with the given elements.
        Type Parameters:
        A - the element type
        Parameters:
        first - the first element
        more - the remaining elements
        Returns:
        an ImmutableNonEmptyVector<A>
      • builder

        static <A> VectorBuilder<A> builder()
        Creates a new VectorBuilder.
        Type Parameters:
        A - the element type
        Returns:
        an empty VectorBuilder
      • builder

        static <A> VectorBuilder<A> builder​(int initialCapacity)
        Creates a new VectorBuilder with an initial capacity hint.
        Type Parameters:
        A - the element type
        Parameters:
        initialCapacity - an initial capacity hint. Must be >= 0.
        Returns:
        an empty VectorBuilder
      • fill

        static <A> ImmutableVector<A> fill​(int size,
                                           A value)
        Creates an ImmutableVector that repeats the same element size times.

        Uses O(1) memory.

        See NonEmptyVector.fill(int, A) if you require an ImmutableNonEmptyVector to be returned.

        Type Parameters:
        A - the element type
        Parameters:
        size - the number of elements. Must be >= 0.
        value - the value that will be repeated for all elements of the ImmutableVector
        Returns:
        an ImmutableVector<A> of size elements, with each element having the value value
      • lazyFill

        static <A> ImmutableVector<A> lazyFill​(int size,
                                               com.jnape.palatable.lambda.functions.Fn1<java.lang.Integer,​A> valueSupplier)
        Creates an ImmutableVector where elements are lazily evaluated.

        Uses O(1) memory.

        See NonEmptyVector.lazyFill(int, com.jnape.palatable.lambda.functions.Fn1<java.lang.Integer, A>) if you require a ImmutableNonEmptyVector to be returned.

        Type Parameters:
        A - the element type
        Parameters:
        size - the number of elements. Must be >= 0.
        valueSupplier - a function that accepts an index and returns the computed value for that index. 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>
      • range

        static ImmutableVector<java.lang.Integer> range​(int size)
        Creates an ImmutableVector<Integer> containing elements 0..size - 1. In other words, each element of the returned Vector will contains its index.

        Uses O(1) memory.

        Parameters:
        size - the number of elements. Must be >= 0. If 0, the returned ImmutableVector will be empty.
        Returns:
        an ImmutableVector<Integer>
      • wrap

        static <A> Vector<A> wrap​(A[] underlying)
        Creates a Vector that wraps an array.

        Does not make any copies of the given array. The created Vector will hold on to a reference to the array, but will never alter it in any way.

        Bearers of the created Vector will be unable to gain access to the underlying array, so it is safe to share.

        Since no copy is made, be aware that anyone that holds a direct reference to the array can still mutate it. Use copyFrom(java.lang.Iterable<A>) instead if you want to avoid this situation.

        Type Parameters:
        A - the element type
        Parameters:
        underlying - array to wrap; not null
        Returns:
        a Vector<A>
      • wrap

        static <A> Vector<A> wrap​(java.util.List<A> underlying)
        Creates a Vector that wraps a java.util.List.

        Does not make any copies of the given List. The created Vector will hold a reference to the given List, but will not alter it in any way.

        Bearers of the created Vector will be unable to gain access to the underlying List, so it is safe to share.

        Since no copy is made, be aware that anyone that holds a direct reference to the List can still mutate it. Mutating the List is not advised. Operations that change the size of the underlying List will result in unpredictable behavior. Use copyFrom(java.lang.Iterable<A>) if you want to avoid this situation.

        Type Parameters:
        A - the element type
        Parameters:
        underlying - List to wrap; not null
        Returns:
        a Vector<A>
      • copyFrom

        static <A> ImmutableVector<A> copyFrom​(java.lang.Iterable<A> source)
        Creates an ImmutableVector that is copied from any Iterable.

        The entire Iterable will be eagerly iterated. Be careful not to pass in an infinite Iterable or this method will not terminate.

        If necessary to guarantee immutability, this method will make a copy of the data provided. If source is an untransformed ImmutableVector, it will be returned directly.

        Type Parameters:
        A - the element type
        Parameters:
        source - an Iterable<A> that will be iterated eagerly in its entirety; not null
        Returns:
        an ImmutableVector<A>
      • copyFrom

        static <A> ImmutableVector<A> copyFrom​(A[] source)
        Creates an ImmutableVector that is copied from an array.
        Type Parameters:
        A - the element type
        Parameters:
        source - the array to copy from. Not null. This method will not alter or hold on to a reference of this array.
        Returns:
        an ImmutableVector<A>
      • copyFrom

        static <A> ImmutableVector<A> copyFrom​(int maxCount,
                                               java.lang.Iterable<A> source)
        Creates an ImmutableVector that is copied from any Iterable, but consuming a maximum number of elements.

        The Iterable will be eagerly iterated, but only up to a maximum of maxCount elements. If maxCount elements are not available, then the all of the elements available will be returned.

        This method will make a copy of the data provided, unless source is an untransformed ImmutableVector and its size is less than or equal to maxCount, in which case it will be returned directly.

        If source is an ImmutableVector that is greater than maxCount in size, a copy will always be made, therefore making it memory-safe to take a small slice of a huge Vector that you no longer need.

        Type Parameters:
        A - the element type
        Parameters:
        maxCount - the maximum number of elements to consume from the source. Must be >= 0.
        source - an Iterable<A> that will be iterated eagerly for up to maxCount elements. Not null. It is safe for source to be infinite.
        Returns:
        an ImmutableVector that contains at most maxCount elements
      • copyFrom

        static <A> ImmutableVector<A> copyFrom​(int maxCount,
                                               A[] source)
        Returns a new ImmutableVector that is copied from an array.
        Type Parameters:
        A - the element type
        Parameters:
        maxCount - the maximum number of elements to copy from the array. Must be >= 0.
        source - the array to copy from. Not null. This method will not alter or hold on to a reference of this array.
        Returns:
        an ImmutableVector<A>
      • copySliceFrom

        static <A> ImmutableVector<A> copySliceFrom​(int startIndex,
                                                    int endIndexExclusive,
                                                    java.lang.Iterable<A> source)
        Creates an ImmutableVector by copying a slice from an Iterable.

        The Iterable will be eagerly iterated, but only for the number of elements needed to fulfill the requested slice. If not enough elements are not available, then this method yields as many elements that were available.

        This method will make a copy of the data provided, except in the case startIndex is 0 and source is an ImmutableVector whose size is less than or equal to count, in which case it will be returned directly.

        It is memory-safe to use this method to take a small slice of a huge Vector that you no longer need.

        Type Parameters:
        A - the element type
        Parameters:
        startIndex - the index of the element to begin the slice. Must be >= 0. May exceed the size of the Iterable.
        endIndexExclusive - the end index (exclusive) of the slice. Must be >= startIndex. May exceed the size of the Iterable.
        source - an Iterable<A> that will be iterated eagerly for up to endIndexExclusive elements. Not null. It is safe for source to be infinite.
        Returns:
        an ImmutableVector<A>