Interface NonEmptyIterable<A>

    • Method Detail

      • head

        A head()
        Returns the first element.
        Returns:
        an element of type A
      • tail

        EnhancedIterable<A> tail()
        Returns an EnhancedIterable containing all subsequent elements of this one beyond the first.
        Returns:
        an EnhancedIterable<A>
      • concat

        default NonEmptyIterable<A> concat​(java.lang.Iterable<A> other)
        Lazily concatenates an Iterable to the end of this NonEmptyIterable, yielding a new NonEmptyIterable.
        Specified by:
        concat in interface EnhancedIterable<A>
        Parameters:
        other - an Iterable
        Returns:
        a NonEmptyIterable<A>
      • fmap

        default <B> NonEmptyIterable<B> fmap​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends B> f)
        Returns a new NonEmptyIterable by applying a function to all elements of this NonEmptyIterable.
        Specified by:
        fmap in interface EnhancedIterable<A>
        Specified by:
        fmap in interface com.jnape.palatable.lambda.functor.Functor<A,​EnhancedIterable<?>>
        Type Parameters:
        B - the type returned by f
        Parameters:
        f - a function from A to B. This function should be referentially transparent and not perform side-effects. It may be called zero or more times for each element.
        Returns:
        a NonEmptyIterable<B>
      • isEmpty

        default boolean isEmpty()
        Always returns false, as a NonEmptyIterable is never empty.
        Specified by:
        isEmpty in interface EnhancedIterable<A>
        Returns:
        false
      • intersperse

        default NonEmptyIterable<A> intersperse​(A separator)
        Returns a new NonEmptyIterable with the provided separator value injected between each value of this NonEmptyIterable.

        If this NonEmptyIterable contains only one element, it is left untouched.

        Specified by:
        intersperse in interface EnhancedIterable<A>
        Parameters:
        separator - the separator value
        Returns:
        a NonEmptyIterable<A>
      • iterator

        default java.util.Iterator<A> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<A>
      • magnetizeBy

        default NonEmptyIterable<? extends NonEmptyIterable<A>> magnetizeBy​(com.jnape.palatable.lambda.functions.Fn2<A,​A,​java.lang.Boolean> predicate)
        Returns an Iterable of contiguous groups of elements in this NonEmptyIterable that match a predicate pairwise.
        Specified by:
        magnetizeBy in interface EnhancedIterable<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 NonEmptyIterable<NonEmptyIterable<A>> containing the contiguous groups
      • prependAll

        default NonEmptyIterable<A> prependAll​(A separator)
        Returns a new NonEmptyIterable with the provided separator value injected before each value of this NonEmptyIterable.
        Specified by:
        prependAll in interface EnhancedIterable<A>
        Parameters:
        separator - the separator value
        Returns:
        a NonEmptyIterable<A>
      • toFinite

        default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyFiniteIterable<A>> toFinite()
        Converts this NonEmptyIterable to an NonEmptyFiniteIterable if there is enough information to do so without iterating it.

        Note that if this method returns nothing(), it does NOT necessarily mean this NonEmptyIterable is infinite.

        Specified by:
        toFinite in interface EnhancedIterable<A>
        Returns:
        a Maybe<NonEmptyFiniteIterable<A>
      • toNonEmpty

        default com.jnape.palatable.lambda.adt.Maybe<? extends NonEmptyIterable<A>> toNonEmpty()
        Always succeeds because NonEmptyIterables are always non-empty.
        Specified by:
        toNonEmpty in interface EnhancedIterable<A>
        Returns:
        this NonEmptyIterable wrapped in a `just`
      • zipWith

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

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

        Type Parameters:
        B - the element type of the other Iterable
        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 Iterable
        Returns:
        an NonEmptyIterable<C>
      • zipWith

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

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

        Type Parameters:
        B - the element type of the other Iterable
        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 Iterable
        Returns:
        an NonEmptyFiniteIterable<C>
      • nonEmptyIterable

        static <A> NonEmptyIterable<A> nonEmptyIterable​(A head,
                                                        java.lang.Iterable<A> tail)
        Creates a NonEmptyIterable.
        Type Parameters:
        A - the element type
        Parameters:
        head - the first element
        tail - the remaining elements. May be empty.
        Returns:
        a NonEmptyIterable<A>
      • of

        @SafeVarargs
        static <A> ImmutableNonEmptyFiniteIterable<A> of​(A first,
                                                         A... more)
        Creates a NonEmptyIterable containing the given elements.

        Note that this method actually returns an ImmutableNonEmptyFiniteIterable, which is also a NonEmptyIterable.

        Type Parameters:
        A - the element type
        Parameters:
        first - the first element
        more - the remaining elements
        Returns:
        an ImmutableNonEmptyFiniteIterable<A>
      • repeat

        static <A> ImmutableNonEmptyIterable<A> repeat​(A element)
        Returns an infinite ImmutableNonEmptyIterable that repeatedly iterates a given element.
        Type Parameters:
        A - the element type
        Parameters:
        element - the value to repeat
        Returns:
        an ImmutableNonEmptyIterable<A>