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>
    A Vector 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, and ImmutableVector, provides the following benefits:

    • ImmutableNonEmptyVector#fmap always returns a ImmutableNonEmptyVector.
    • ImmutableNonEmptyVector#reverse always returns a ImmutableNonEmptyVector.
    • ImmutableNonEmptyVector#zipWithIndex always returns a ImmutableNonEmptyVector.
    • 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 new NonEmptyVectorBuilder with an initial capacity hint.
      static <A> NonEmptyVectorBuilder<A> builder​(A first)
      Creates a new NonEmptyVectorBuilder.
      default <B> ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​B>> cross​(ImmutableNonEmptyVector<B> other)
      Returns the cartesian product of this ImmutableNonEmptyVector with another ImmutableNonEmptyVector.
      default <B> ImmutableNonEmptyVector<B> fmap​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends B> f)
      Maps a function over this ImmutableNonEmptyVector.
      default ImmutableVector<A> init()
      Returns the init of this ImmutableNonEmptyVector.
      default software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<? extends ImmutableNonEmptyVector<A>> magnetizeBy​(com.jnape.palatable.lambda.functions.Fn2<A,​A,​java.lang.Boolean> predicate)
      Returns an ImmutableNonEmptyFiniteIterable of contiguous groups of elements in this ImmutableNonEmptyVector that match a predicate pairwise.
      static <A> ImmutableNonEmptyVector<A> of​(A first, A... more)
      Creates a ImmutableNonEmptyVector with the given elements.
      default ImmutableNonEmptyVector<A> reverse()
      Creates an ImmutableNonEmptyVector with this ImmutableNonEmptyVector's elements in reversed order.
      default ImmutableVector<A> tail()
      Returns the tail of this ImmutableNonEmptyVector.
      default ImmutableNonEmptyVector<A> toImmutable()
      Returns an ImmutableNonEmptyVector containing the same elements as this one.
      default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>> toNonEmpty()
      Attempts to convert this ImmutableVector to an ImmutableNonEmptyVector.
      default ImmutableNonEmptyVector<A> toNonEmptyOrThrow()
      Attempts to convert this ImmutableVector to a ImmutableNonEmptyVector.
      default <B,​C>
      ImmutableNonEmptyVector<C>
      zipWith​(com.jnape.palatable.lambda.functions.Fn2<A,​B,​C> fn, ImmutableNonEmptyVector<B> other)
      Zips together this ImmutableNonEmptyVector with another ImmutableNonEmptyVector by applying a zipping function.
      default ImmutableNonEmptyVector<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​java.lang.Integer>> zipWithIndex()
      Zips this ImmutableNonEmptyVector 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 com.jnape.palatable.lambda.functor.Functor

        coerce
      • 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 java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface software.kes.enhancediterables.NonEmptyFiniteIterable

        concat, concat, cross, cycle, distinct, intersperse, prependAll, reduceLeft, reduceRight, toFinite, zipWith
      • Methods inherited from interface software.kes.enhancediterables.NonEmptyIterable

        concat, 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 this ImmutableNonEmptyVector with another ImmutableNonEmptyVector.

        Does not make copies of any underlying collections.

        The returned ImmutableNonEmptyVector 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 ImmutableNonEmptyVector
        Parameters:
        other - an ImmutableNonEmptyVector 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 this ImmutableNonEmptyVector.

        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 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<?>>
        Specified by:
        fmap in interface software.kes.enhancediterables.ImmutableFiniteIterable<A>
        Specified by:
        fmap in interface software.kes.enhancediterables.ImmutableIterable<A>
        Specified by:
        fmap in interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
        Specified by:
        fmap in interface software.kes.enhancediterables.ImmutableNonEmptyIterable<A>
        Specified by:
        fmap in interface ImmutableVector<A>
        Specified by:
        fmap in interface software.kes.enhancediterables.NonEmptyFiniteIterable<A>
        Specified by:
        fmap in interface software.kes.enhancediterables.NonEmptyIterable<A>
        Specified by:
        fmap in interface NonEmptyVector<A>
        Specified by:
        fmap in interface Vector<A>
        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:
        an ImmutableNonEmptyVector<B> of the same size
      • init

        default ImmutableVector<A> init()
        Returns the init of this ImmutableNonEmptyVector.

        The init of a ImmutableNonEmptyVector is the same Vector with the last element dropped. May be empty.

        Does not make copies of any underlying collections.

        Specified by:
        init in interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
        Specified by:
        init in interface software.kes.enhancediterables.NonEmptyFiniteIterable<A>
        Specified by:
        init in interface NonEmptyVector<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 an ImmutableNonEmptyFiniteIterable of contiguous groups of elements in this ImmutableNonEmptyVector that match a predicate pairwise.
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.FiniteIterable<A>
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.ImmutableFiniteIterable<A>
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.ImmutableIterable<A>
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.ImmutableNonEmptyIterable<A>
        Specified by:
        magnetizeBy in interface ImmutableVector<A>
        Specified by:
        magnetizeBy in interface software.kes.enhancediterables.NonEmptyFiniteIterable<A>
        Specified by:
        magnetizeBy in interface software.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 an ImmutableNonEmptyVector with this ImmutableNonEmptyVector's elements in reversed order.

        Does not make copies of any underlying collections.

        Specified by:
        reverse in interface software.kes.enhancediterables.FiniteIterable<A>
        Specified by:
        reverse in interface software.kes.enhancediterables.ImmutableFiniteIterable<A>
        Specified by:
        reverse in interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
        Specified by:
        reverse in interface ImmutableVector<A>
        Specified by:
        reverse in interface software.kes.enhancediterables.NonEmptyFiniteIterable<A>
        Specified by:
        reverse in interface NonEmptyVector<A>
        Specified by:
        reverse in interface Vector<A>
        Returns:
        an ImmutableNonEmptyVector<A>
      • tail

        default ImmutableVector<A> tail()
        Returns the tail of this ImmutableNonEmptyVector.

        The tail of an ImmutableNonEmptyVector is the same ImmutableNonEmptyVector with the first element dropped. May be empty.

        Does not make copies of any underlying collections.

        Specified by:
        tail in interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
        Specified by:
        tail in interface software.kes.enhancediterables.ImmutableNonEmptyIterable<A>
        Specified by:
        tail in interface software.kes.enhancediterables.NonEmptyFiniteIterable<A>
        Specified by:
        tail in interface software.kes.enhancediterables.NonEmptyIterable<A>
        Specified by:
        tail in interface NonEmptyVector<A>
        Returns:
        an ImmutableVector<A>
      • toNonEmpty

        default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptyVector<A>> toNonEmpty()
        Attempts to convert this ImmutableVector to an ImmutableNonEmptyVector.

        Since this will always be successful for ImmutableNonEmptyVectors, this method always returns itself wrapped in a Maybe.just(A).

        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>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.ImmutableFiniteIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.ImmutableIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.ImmutableNonEmptyFiniteIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.ImmutableNonEmptyIterable<A>
        Specified by:
        toNonEmpty in interface ImmutableVector<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.NonEmptyFiniteIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.NonEmptyIterable<A>
        Specified by:
        toNonEmpty in interface NonEmptyVector<A>
        Specified by:
        toNonEmpty in interface Vector<A>
        Returns:
        this ImmutableNonEmptyVector wrapped in a Maybe.just(A)
      • zipWith

        default <B,​C> ImmutableNonEmptyVector<C> zipWith​(com.jnape.palatable.lambda.functions.Fn2<A,​B,​C> fn,
                                                               ImmutableNonEmptyVector<B> other)
        Zips together this ImmutableNonEmptyVector with another ImmutableNonEmptyVector 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 other ImmutableNonEmptyVector
        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 ImmutableNonEmptyVector
        Returns:
        A ImmutableNonEmptyVector<C>
      • zipWithIndex

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

        Does not make copies of any underlying collections.

        Specified by:
        zipWithIndex in interface ImmutableVector<A>
        Specified by:
        zipWithIndex in interface NonEmptyVector<A>
        Specified by:
        zipWithIndex in interface Vector<A>
        Returns:
        a new ImmutableNonEmptyVector containing pairs consisting of all elements of this ImmutableNonEmptyVector paired with their index. Indices start at 0.
      • 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> NonEmptyVectorBuilder<A> builder​(A first)
        Creates a new NonEmptyVectorBuilder.
        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 new NonEmptyVectorBuilder 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