Interface ImmutableFiniteIterable<A>

    • Method Detail

      • cross

        default <B> ImmutableFiniteIterable<com.jnape.palatable.lambda.adt.hlist.Tuple2<A,​B>> cross​(ImmutableFiniteIterable<B> other)
        Returns the lazily computed cartesian product of this ImmutableFiniteIterable with another ImmutableFiniteIterable.
        Type Parameters:
        B - the type of the other ImmutableFiniteIterable
        Parameters:
        other - an ImmutableFiniteIterable of any type
        Returns:
        a ImmutableFiniteIterable<Tuple2<A, B>>
      • cycle

        default ImmutableIterable<A> cycle()
        Returns an infinite ImmutableIterable that repeatedly cycles this ImmutableFiniteIterable's elements, in order.
        Specified by:
        cycle in interface FiniteIterable<A>
        Returns:
        an ImmutableIterable<A>
      • drop

        default ImmutableFiniteIterable<A> drop​(int count)
        Returns a new ImmutableFiniteIterable that drops the first count elements of this ImmutableFiniteIterable.
        Specified by:
        drop in interface EnhancedIterable<A>
        Specified by:
        drop in interface FiniteIterable<A>
        Specified by:
        drop in interface ImmutableIterable<A>
        Parameters:
        count - the number of elements to drop from this ImmutableFiniteIterable. Must be >= 0. May exceed size of this ImmutableFiniteIterable, in which case, the result will be an empty ImmutableFiniteIterable.
        Returns:
        an ImmutableFiniteIterable<A>
      • dropWhile

        default ImmutableFiniteIterable<A> dropWhile​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends java.lang.Boolean> predicate)
        Returns a new ImmutableFiniteIterable that skips the first contiguous group of elements of this ImmutableFiniteIterable that satisfy a predicate.

        Iteration begins at the first element for which the predicate evaluates to false.

        Specified by:
        dropWhile in interface EnhancedIterable<A>
        Specified by:
        dropWhile in interface FiniteIterable<A>
        Specified by:
        dropWhile in interface ImmutableIterable<A>
        Parameters:
        predicate - a predicate; should be referentially transparent and not have side-effects
        Returns:
        a ImmutableFiniteIterable<A>
      • filter

        default ImmutableFiniteIterable<A> filter​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends java.lang.Boolean> predicate)
        Returns a new ImmutableFiniteIterable that contains all elements of this ImmutableFiniteIterable that satisfy a predicate.
        Specified by:
        filter in interface EnhancedIterable<A>
        Specified by:
        filter in interface FiniteIterable<A>
        Specified by:
        filter in interface ImmutableIterable<A>
        Parameters:
        predicate - a predicate; should be referentially transparent and not have side-effects
        Returns:
        a ImmutableFiniteIterable<A>
      • fmap

        default <B> ImmutableFiniteIterable<B> fmap​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends B> f)
        Returns a new ImmutableFiniteIterable by applying a function to all elements of this ImmutableFiniteIterable.
        Specified by:
        fmap in interface EnhancedIterable<A>
        Specified by:
        fmap in interface FiniteIterable<A>
        Specified by:
        fmap in interface com.jnape.palatable.lambda.functor.Functor<A,​EnhancedIterable<?>>
        Specified by:
        fmap in interface ImmutableIterable<A>
        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:
        an ImmutableFiniteIterable<B>
      • inits

        default ImmutableNonEmptyFiniteIterable<? extends ImmutableFiniteIterable<A>> inits()
        Returns an ImmutableNonEmptyIterable containing all of the subsequences of initial elements of this ImmutableFiniteIterable, ordered by size, starting with the empty list. Example: ImmutableFiniteIterable.of(1, 2, 3).inits(); // [[], [1], [1, 2], [1, 2, 3]]
        Specified by:
        inits in interface FiniteIterable<A>
        Returns:
        an ImmutableNonEmptyFiniteIterable<ImmutableFiniteIterable<A>>
      • intersperse

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

        If this ImmutableFiniteIterable contains fewer than two elements, it is left untouched.

        Specified by:
        intersperse in interface EnhancedIterable<A>
        Specified by:
        intersperse in interface FiniteIterable<A>
        Specified by:
        intersperse in interface ImmutableIterable<A>
        Parameters:
        separator - the separator value
        Returns:
        a ImmutableFiniteIterable<A>
      • magnetizeBy

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

        default <B,​C> com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends ImmutableFiniteIterable<B>,​? extends ImmutableFiniteIterable<C>> partition​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends com.jnape.palatable.lambda.adt.coproduct.CoProduct2<B,​C,​?>> function)
        Partitions this ImmutableFiniteIterable given a disjoint mapping function.
        Specified by:
        partition in interface EnhancedIterable<A>
        Specified by:
        partition in interface FiniteIterable<A>
        Specified by:
        partition in interface ImmutableIterable<A>
        Type Parameters:
        B - the output left Iterable element type, as well as the CoProduct2 A type
        C - the output right Iterable element type, as well as the CoProduct2 B type
        Parameters:
        function - the mapping function
        Returns:
        a Tuple2<ImmutableFiniteIterable&lt;B&gt;, ImmutableFiniteIterable&lt;C&gt;>
      • prependAll

        default ImmutableFiniteIterable<A> prependAll​(A separator)
        Returns a new ImmutableFiniteIterable with the provided separator value injected before each value of this ImmutableFiniteIterable.

        If this ImmutableFiniteIterable is empty, it is left untouched.

        Specified by:
        prependAll in interface EnhancedIterable<A>
        Specified by:
        prependAll in interface FiniteIterable<A>
        Specified by:
        prependAll in interface ImmutableIterable<A>
        Parameters:
        separator - the separator value
        Returns:
        a ImmutableFiniteIterable<A>
      • reverse

        default ImmutableFiniteIterable<A> reverse()
        Returns a reversed representation of this ImmutableFiniteIterable.

        Note that reversing is deferred until the returned Iterable is iterated.

        Specified by:
        reverse in interface FiniteIterable<A>
        Returns:
        an ImmutableFiniteIterable<A>
      • slide

        default ImmutableFiniteIterable<? extends ImmutableNonEmptyFiniteIterable<A>> slide​(int k)
        "Slides" a window of k elements across the ImmutableFiniteIterable by one element at a time.

        Example: ImmutableFiniteIterable.of(1, 2, 3, 4, 5).slide(2); // [[1, 2], [2, 3], [3, 4], [4, 5]]

        Specified by:
        slide in interface EnhancedIterable<A>
        Specified by:
        slide in interface FiniteIterable<A>
        Specified by:
        slide in interface ImmutableIterable<A>
        Parameters:
        k - the number of elements in the sliding window. Must be >= 1.
        Returns:
        an ImmutableFiniteIterable<ImmutableNonEmptyFiniteIterable<A>>
      • span

        default com.jnape.palatable.lambda.adt.hlist.Tuple2<? extends ImmutableFiniteIterable<A>,​? extends ImmutableFiniteIterable<A>> span​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends java.lang.Boolean> predicate)
        Returns a Tuple2 where the first slot is the front contiguous elements of this ImmutableFiniteIterable matching a predicate and the second slot is all the remaining elements.
        Specified by:
        span in interface EnhancedIterable<A>
        Specified by:
        span in interface FiniteIterable<A>
        Specified by:
        span in interface ImmutableIterable<A>
        Parameters:
        predicate - a predicate; should be referentially transparent and not have side-effects
        Returns:
        a Tuple2<ImmutableFiniteIterable&lt;B&gt;, ImmutableFiniteIterable&lt;C&gt;>
      • tails

        default ImmutableNonEmptyIterable<? extends ImmutableFiniteIterable<A>> tails()
        Returns an ImmutableNonEmptyIterable containing all of the subsequences of tail elements of this ImmutableFiniteIterable, ordered by size, starting with the full list. Example: ImmutableFiniteIterable.of(1, 2, 3).tails(); // [[1, 2, 3], [2, 3], [3], []]
        Specified by:
        tails in interface EnhancedIterable<A>
        Specified by:
        tails in interface FiniteIterable<A>
        Specified by:
        tails in interface ImmutableIterable<A>
        Returns:
        an ImmutableNonEmptyIterable<ImmutableFiniteIterable<A>>
      • takeWhile

        default ImmutableFiniteIterable<A> takeWhile​(com.jnape.palatable.lambda.functions.Fn1<? super A,​? extends java.lang.Boolean> predicate)
        Returns a new ImmutableFiniteIterable that limits to the first contiguous group of elements of this FiniteIterable that satisfy a predicate.

        Iteration ends at, but does not include, the first element for which the predicate evaluates to false.

        Specified by:
        takeWhile in interface EnhancedIterable<A>
        Specified by:
        takeWhile in interface FiniteIterable<A>
        Specified by:
        takeWhile in interface ImmutableIterable<A>
        Parameters:
        predicate - a predicate; should be referentially transparent and not have side-effects
        Returns:
        a ImmutableFiniteIterable<A>
      • zipWith

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

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

        Specified by:
        zipWith in interface ImmutableIterable<A>
        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 ImmutableFiniteIterable<C>
      • copyFrom

        static <A> ImmutableFiniteIterable<A> copyFrom​(FiniteIterable<A> source)
        Creates an ImmutableFiniteIterable by copying elements from a FiniteIterable.

        If source is already an ImmutableFiniteIterable, this method will return it without copying.

        Type Parameters:
        A - the element type
        Parameters:
        source - the source to copy from
        Returns:
        an ImmutableFiniteIterable<A>
      • copyFrom

        static <A> ImmutableFiniteIterable<A> copyFrom​(java.util.Collection<A> source)
        Creates an ImmutableFiniteIterable by copying elements from a Collection.
        Type Parameters:
        A - the element type
        Parameters:
        source - the source to copy from
        Returns:
        an ImmutableFiniteIterable<A>
      • copyFrom

        static <A> ImmutableFiniteIterable<A> copyFrom​(int maxCount,
                                                       java.lang.Iterable<A> source)
        Creates an ImmutableFiniteIterable by copying elements from an Iterable.

        If source is already an ImmutableIterable, no copying will be performed.

        Type Parameters:
        A - the element type
        Parameters:
        maxCount - the maximum number of elements to take from the supplied Iterable. Must be >= 0. May exceed size of the Iterable, in which case, the result will contain as many elements available.
        source - the source to copy from
        Returns:
        an ImmutableFiniteIterable<A>
      • emptyImmutableFiniteIterable

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

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

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

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