Package fj.data

Class List<A>

  • All Implemented Interfaces:
    java.lang.Iterable<A>
    Direct Known Subclasses:
    List.Cons, List.Nil

    public abstract class List<A>
    extends java.lang.Object
    implements java.lang.Iterable<A>
    Provides an in-memory, immutable, singly linked list.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  List.Buffer<A>
      A mutable, singly linked list.
      private static class  List.Cons<A>  
      private static class  List.Nil<A>  
      static class  List.Optic
      Optic factory methods for a List
      static class  List.Unsafe  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private List()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean allEqual​(Equal<A> eq)
      Returns whether or not all elements in the list are equal according to the given equality test.
      List<A> append​(List<A> as)
      Appends the given list to this list.
      <B> List<B> apply​(List<F<A,​B>> lf)
      Performs function application within a list (applicative functor pattern).
      A[] array​(java.lang.Class<A[]> c)
      Returns an array from this list.
      static <A> List<A> arrayList​(A... as)
      Constructs a list from the given elements.
      static F<List<java.lang.Character>,​java.lang.String> asString()
      A first-class asString.
      static java.lang.String asString​(List<java.lang.Character> cs)
      Returns a string from the given list of characters.
      <B,​C,​D,​E,​F$,​G,​H,​I>
      List<I>
      bind​(List<B> lb, List<C> lc, List<D> ld, List<E> le, List<F$> lf, List<G> lg, List<H> lh, F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​F<H,​I>>>>>>>> f)
      Binds the given function across each element of this list and the given lists with a final join.
      <B,​C,​D,​E,​F$,​G,​H>
      List<H>
      bind​(List<B> lb, List<C> lc, List<D> ld, List<E> le, List<F$> lf, List<G> lg, F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​H>>>>>>> f)
      Binds the given function across each element of this list and the given lists with a final join.
      <B,​C,​D,​E,​F$,​G>
      List<G>
      bind​(List<B> lb, List<C> lc, List<D> ld, List<E> le, List<F$> lf, F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​G>>>>>> f)
      Binds the given function across each element of this list and the given lists with a final join.
      <B,​C,​D,​E,​F$>
      List<F$>
      bind​(List<B> lb, List<C> lc, List<D> ld, List<E> le, F<A,​F<B,​F<C,​F<D,​F<E,​F$>>>>> f)
      Binds the given function across each element of this list and the given lists with a final join.
      <B,​C,​D,​E>
      List<E>
      bind​(List<B> lb, List<C> lc, List<D> ld, F<A,​F<B,​F<C,​F<D,​E>>>> f)
      Binds the given function across each element of this list and the given lists with a final join.
      <B,​C,​D>
      List<D>
      bind​(List<B> lb, List<C> lc, F<A,​F<B,​F<C,​D>>> f)
      Binds the given function across each element of this list and the given lists with a final join.
      <B,​C>
      List<C>
      bind​(List<B> lb, F<A,​F<B,​C>> f)
      Binds the given function across each element of this list and the given list with a final join.
      <B,​C>
      List<C>
      bind​(List<B> lb, F2<A,​B,​C> f)
      Binds the given function across each element of this list and the given list with a final join.
      <B> List<B> bind​(F<A,​List<B>> f)
      Binds the given function across each element of this list with a final join.
      static <A,​B>
      F<F<A,​List<B>>,​F<List<A>,​List<B>>>
      bind_()
      Provides a first-class version of bind()
      P2<List<A>,​List<A>> breakk​(F<A,​java.lang.Boolean> p)
      Returns a tuple where the first element is the longest prefix of this list that does not satisfy the given predicate and the second element is the remainder of the list.
      static <A> F<A,​F<List<A>,​List<A>>> cons()
      Returns a function that prepends (cons) an element to a list to produce a new list.
      List<A> cons​(A a)
      Prepends (cons) the given element to this list to product a new list.
      static <A> List<A> cons​(A head, List<A> tail)
      Prepends the given head element to the given tail element to produce a new list.
      static <A> F<A,​List<A>> cons​(List<A> tail)
      Returns a function that prepends a value to the given list.
      static <A> F2<A,​List<A>,​List<A>> cons_()  
      static <A> F<List<A>,​List<A>> cons_​(A a)
      Returns a function that prepends the given value to a list.
      List<A> conss​(A a)
      Prepends (cons) the given element to this list to product a new list.
      List<A> delete​(A a, Equal<A> e)
      Removes the first element that equals the given object.
      List<A> drop​(int i)
      Drops the given number of elements from the head of this list if they are available.
      List<A> dropWhile​(F<A,​java.lang.Boolean> f)
      Removes elements from the head of this list that do not match the given predicate function until an element is found that does match or the list is exhausted.
      Option<java.lang.Integer> elementIndex​(Equal<A> e, A a)
      Returns the index of the first element in this list which is equal (by the given equality) to the query element, or None if there is no such element.
      boolean equals​(java.lang.Object obj)
      Perform an equality test on this list which delegates to the .equals() method of the member instances.
      boolean exists​(F<A,​java.lang.Boolean> f)
      Returns true if the predicate holds for at least one of the elements of this list, false otherwise (false for the empty list).
      List<A> filter​(F<A,​java.lang.Boolean> f)
      Filters elements from this list by returning only elements which produce true when the given function is applied to them.
      Option<A> find​(F<A,​java.lang.Boolean> f)
      Finds the first occurrence of an element that matches the given predicate or no value if no elements match.
      static <A,​B>
      F<F<B,​F<A,​B>>,​F<B,​F<List<A>,​B>>>
      foldLeft()
      Provides a first-class version of foldLeft.
      <B> B foldLeft​(F<B,​F<A,​B>> f, B b)
      Performs a left-fold reduction across this list.
      <B> B foldLeft​(F2<B,​A,​B> f, B b)
      Performs a left-fold reduction across this list.
      A foldLeft1​(F<A,​F<A,​A>> f)
      Takes the first 2 elements of the list and applies the function to them, then applies the function to the result and the third element and so on.
      A foldLeft1​(F2<A,​A,​A> f)
      Takes the first 2 elements of the list and applies the function to them, then applies the function to the result and the third element and so on.
      <B> B foldRight​(F<A,​F<B,​B>> f, B b)
      Performs a right-fold reduction across this list.
      <B> B foldRight​(F2<A,​B,​B> f, B b)
      Performs a right-fold reduction across this list.
      <B> Trampoline<B> foldRightC​(F2<A,​B,​B> f, B b)
      Performs a right-fold reduction across this list in O(1) stack space.
      boolean forall​(F<A,​java.lang.Boolean> f)
      Returns true if the predicate holds for all of the elements of this list, false otherwise (true for the empty list).
      Unit foreach​(F<A,​Unit> f)
      Performs a side-effect for each element of this list.
      void foreachDoEffect​(Effect1<A> f)
      Performs a side-effect for each element of this list.
      static <A> List<A> fromIterator​(java.util.Iterator<A> it)
      Constructs a list from the given Iterator.
      static F<java.lang.String,​List<java.lang.Character>> fromString()
      A first-class fromString.
      static List<java.lang.Character> fromString​(java.lang.String s)
      Returns a list of characters from the given string.
      List<List<A>> group​(Equal<A> e)
      Groups elements according to the given equality implementation by longest sequence of equal elements.
      <B,​C,​D>
      TreeMap<B,​D>
      groupBy​(F<A,​B> keyFunction, F<A,​C> valueFunction, D groupingIdentity, F2<C,​D,​D> groupingAcc, Ord<B> keyOrd)
      Groups the elements of this list by a given keyFunction, applies the valueFunction and accumulates the mapped values with the given grouping accumulator function on the grouping identity.
      <B,​C>
      TreeMap<B,​C>
      groupBy​(F<A,​B> keyFunction, F<A,​C> valueFunction, Monoid<C> monoid, Ord<B> keyOrd)
      Groups the elements of this list by a given keyFunction into a TreeMap and transforms the matching elements with the given valueFunction.
      <B,​C>
      TreeMap<B,​List<C>>
      groupBy​(F<A,​B> keyFunction, F<A,​C> valueFunction, Ord<B> keyOrd)
      Groups the elements of this list by a given keyFunction into a TreeMap and transforms the matching elements with the given valueFunction.
      <B> TreeMap<B,​List<A>> groupBy​(F<A,​B> keyFunction, Ord<B> keyOrd)
      Groups the elements of this list by a given keyFunction into a TreeMap.
      int hashCode()
      Compute the hash code from this list as a function of the hash codes of its members.
      abstract A head()
      The first element of the linked list or fails for the empty list.
      static <A> F<List<A>,​A> head_()
      First-class head function.
      Option<A> headOption()
      Returns the head of the list, if any.
      A index​(int i)
      Returns the element at the given index if it exists, fails otherwise.
      List<A> init()
      Returns all but the last element of this list.
      List<List<A>> inits()
      Returns the list of initial segments of this list, shortest first.
      List<A> insertBy​(F<A,​F<A,​Ordering>> f, A x)
      Inserts the given element before the first element that is greater than or equal to it according to the given ordering.
      List<A> intercalate​(List<List<A>> as)
      Intersperses this list through the given list then joins the results.
      List<A> intersperse​(A a)
      Intersperses the given argument between each element of this list.
      boolean isEmpty()
      Returns true if this list is empty, false otherwise.
      static <A> F<List<A>,​java.lang.Boolean> isEmpty_()
      Returns a function that determines whether a given list is empty.
      boolean isNotEmpty()
      Returns false if this list is empty, true otherwise.
      static <A> F<List<A>,​java.lang.Boolean> isNotEmpty_()
      Returns a function that determines whether a given list is not empty.
      boolean isPrefixOf​(Equal<A> eq, List<A> xs)  
      boolean isSingle()
      True if and only if the list has one element.
      boolean isSuffixOf​(Equal<A> eq, List<A> xs)  
      static <A> List<A> iterableList​(java.lang.Iterable<A> i)
      Takes the given iterable to a list.
      static <A> List<A> iterateWhile​(F<A,​A> f, F<A,​java.lang.Boolean> p, A a)
      Creates a list where the first item is calculated by applying the function on the third argument, the second item by applying the function on the previous result and so on.
      java.util.Iterator<A> iterator()
      Returns an iterator for this list.
      static <A> List<A> iteratorList​(java.util.Iterator<A> it)
      Constructs a list from the given Iterator.
      static <A> F<List<List<A>>,​List<A>> join()
      A first-class version of join
      static <A> List<A> join​(List<List<A>> o)
      Joins the given list of lists using a bind operation.
      A last()
      Returns the last element of this list.
      int length()
      The length of this list.
      static <A> F<List<A>,​java.lang.Integer> length_()
      First-class length.
      static <A,​B,​C>
      F<List<A>,​F<List<B>,​List<C>>>
      liftM2​(F<A,​F<B,​C>> f)
      Promotes the given function of arity-2 to a function on lists.
      static <A> List<A> list​(A... as)
      Constructs a list from the given elements.
      static <A,​B>
      F2<List<P2<A,​B>>,​A,​Option<B>>
      lookup​(Equal<A> e)
      Returns a partially applied version of lookup(Equal, List, Object).
      static <A,​B>
      Option<B>
      lookup​(Equal<A> e, List<P2<A,​B>> x, A a)
      Returns an associated value with the given key in the list of pairs.
      <B> List<B> map​(F<A,​B> f)
      Maps the given function across this list.
      static <A,​B>
      F<F<A,​B>,​F<List<A>,​List<B>>>
      map_()
      Provides a first-class version of map()
      <B,​C>
      F<B,​List<C>>
      mapM​(F<A,​F<B,​C>> f)
      Maps the given function of arity-2 across this list and returns a function that applies all the resulting functions to a given argument.
      <B> Option<List<B>> mapMOption​(F<A,​Option<B>> f)
      Maps the given function across this list by binding through the Option monad.
      <B> Trampoline<List<B>> mapMTrampoline​(F<A,​Trampoline<B>> f)
      Maps the given function across this list by binding through the Trampoline monad.
      A maximum​(Ord<A> o)
      Returns the maximum element in this list according to the given ordering.
      Option<A> maximumOption​(Ord<A> o)
      Returns the maximum element in this list according to the given ordering.
      A minimum​(Ord<A> o)
      Returns the minimum element in this list according to the given ordering.
      Option<A> minimumOption​(Ord<A> o)
      Returns the minimum element in this list according to the given ordering.
      List<A> minus​(Equal<A> eq, List<A> xs)
      Returns a new list of all the items in this list that do not appear in the given list.
      A mode​(Ord<A> o)
      Returns the most common element in this list.
      static <A> List<A> nil()
      Returns an empty list.
      List<A> nub()
      Removes duplicates according to object equality.
      List<A> nub​(Equal<A> eq)
      Removes duplicates according to the given equality.
      List<A> nub​(Ord<A> o)
      Removes duplicates according to the given ordering.
      A orHead​(F0<A> a)
      Returns the head of this list if there is one or the given argument if this list is empty.
      List<A> orTail​(F0<List<A>> as)
      Returns the tail of this list if there is one or the given argument if this list is empty.
      List<List<A>> partition​(int n)
      Splits this list into lists of the given size.
      P2<List<A>,​List<A>> partition​(F<A,​java.lang.Boolean> f)
      Partitions the list into a tuple where the first element contains the items that satisfy the the predicate f and the second element contains the items that does not.
      static List<java.lang.Integer> range​(int from, int to)
      Returns a list of integers from the given from value (inclusive) to the given to value (exclusive).
      List<A> removeAll​(F<A,​java.lang.Boolean> f)
      Filters elements from this list by returning only elements which produce false when the given function is applied to them.
      static <A> List<A> replicate​(int n, A a)
      Returns a list of the given value replicated the given number of times.
      List<A> reverse()
      Reverse this list in constant stack space.
      <B> List<B> sequence​(List<B> bs)
      Performs a bind across each list element, but ignores the element value each time.
      static <A,​B>
      F<B,​List<A>>
      sequence_​(List<F<B,​A>> fs)
      Turn a list of functions into a function returning a list.
      static <L,​B>
      Either<L,​List<B>>
      sequenceEither​(List<Either<L,​B>> list)
      Sequence the given list and collect the output on the right side of an either.
      static <R,​B>
      Either<List<B>,​R>
      sequenceEitherLeft​(List<Either<B,​R>> list)
      Sequence the given list and collect the output on the left side of an either.
      static <L,​B>
      Either<L,​List<B>>
      sequenceEitherRight​(List<Either<L,​B>> list)
      Sequence the given list and collect the output on the right side of an either.
      static <C,​B>
      F<C,​List<B>>
      sequenceF​(List<F<C,​B>> list)
      Sequence the given list and collect the output as a function.
      static <B> IO<List<B>> sequenceIO​(List<IO<B>> list)
      Sequence the given list and collect the output as an IO.
      static <B> List<List<B>> sequenceList​(List<List<B>> list)
      Sequence the given list and collect the output as an list.
      static <B> Option<List<B>> sequenceOption​(List<Option<B>> list)
      Sequence the given list and collect the output as an list.
      static <B> P1<List<B>> sequenceP1​(List<P1<B>> list)
      Sequence the given list and collect the output as a P1.
      static <B> Seq<List<B>> sequenceSeq​(List<Seq<B>> list)
      Sequence the given list and collect the output as a seq.
      static <B> Set<List<B>> sequenceSet​(Ord<B> ord, List<Set<B>> list)
      Sequence the given list and collect the output as a set; use the given ord to order the set.
      static <B> Stream<List<B>> sequenceStream​(List<Stream<B>> list)
      Sequence the given list and collect the output as a stream.
      static <B> Trampoline<List<B>> sequenceTrampoline​(List<Trampoline<B>> list)
      Sequence the given list and collect the output as a trampoline.
      static <E,​B>
      Validation<E,​List<B>>
      sequenceValidation​(Semigroup<E> semigroup, List<Validation<E,​B>> list)
      Sequence the given list and collect the output as a validation; use the given semigroup to reduce the errors.
      static <A> List<A> single​(A a)
      Returns a list of one element containing the given value.
      List<A> snoc​(A a)
      Appends (snoc) the given element to this list to produce a new list.
      List<A> sort​(Ord<A> o)
      Sorts this list using the given order over elements using a merge sort algorithm.
      P2<List<A>,​List<A>> span​(F<A,​java.lang.Boolean> p)
      Returns a tuple where the first element is the longest prefix of this list that satisfies the given predicate and the second element is the remainder of the list.
      P2<List<A>,​List<A>> splitAt​(int i)
      Splits this list into two lists at the given index.
      abstract List<A> tail()
      The list without the first element or fails for the empty list.
      static <A> F<List<A>,​List<A>> tail_()
      First-class tail function.
      Option<List<A>> tailOption()
      Reutrns the tail of the list, if any.
      List<List<A>> tails()
      Returns the list of final segments of this list, longest first.
      static <A> F<java.lang.Integer,​F<List<A>,​List<A>>> take()
      Provides a first-class version of take.
      List<A> take​(int i)
      Takes the given number of elements from the head of this list if they are available.
      List<A> takeWhile​(F<A,​java.lang.Boolean> f)
      Returns the first elements of the head of this list that match the given predicate function.
      Array<A> toArray()
      Returns a array projection of this list.
      Array<A> toArray​(java.lang.Class<A[]> c)
      Returns a array projection of this list.
      java.lang.Object[] toArrayObject()  
      java.util.Collection<A> toCollection()
      Projects an immutable collection of this list.
      <X> Either<X,​A> toEither​(F0<X> x)
      Returns an either projection of this list; the given argument in Left if empty, or the first element in Right.
      java.util.List<A> toJavaList()  
      Stream<A> toStream()
      Returns a stream projection of this list.
      java.lang.String toString()
      Obtain a string representation of this list using the toString implementations of the members.
      <B,​E>
      Either<E,​List<B>>
      traverseEither​(F<A,​Either<E,​B>> f)
      Traverse through the List with given function.
      <R,​B>
      Either<List<B>,​R>
      traverseEitherLeft​(F<A,​Either<B,​R>> f)
      Traverse this list with the given function and collect the output on the left side of an either.
      <L,​B>
      Either<L,​List<B>>
      traverseEitherRight​(F<A,​Either<L,​B>> f)
      Traverse this list with the given function and collect the output on the right side of an either.
      <C,​B>
      F<C,​List<B>>
      traverseF​(F<A,​F<C,​B>> f)
      Traverse this list with the given function and collect the output as a function.
      <B> IO<List<B>> traverseIO​(F<A,​IO<B>> f)
      Traverse this list with the given function and collect the output as an IO.
      <B> List<List<B>> traverseList​(F<A,​List<B>> f)
      Traverse this list with the given function and collect the output as a list.
      <B> Option<List<B>> traverseOption​(F<A,​Option<B>> f)
      Traverses through the List with the given function
      <B> P1<List<B>> traverseP1​(F<A,​P1<B>> f)
      Traverse this list with the given function and collect the output as a p1.
      <B> Promise<List<B>> traversePromise​(F<A,​Promise<B>> f)  
      <B> Seq<List<B>> traverseSeq​(F<A,​Seq<B>> f)
      Traverse this list with the given function and collect the output as a seq.
      <B> Set<List<B>> traverseSet​(Ord<B> ord, F<A,​Set<B>> f)
      Traverse this list with the given function and collect the output as a set; use the given ord to order the set.
      <B> Stream<List<B>> traverseStream​(F<A,​Stream<B>> f)
      Traverse this list with the given function and collect the output as a stream.
      <B> Trampoline<List<B>> traverseTrampoline​(F<A,​Trampoline<B>> f)
      Traverse this list with the given function and collect the output as a trampoline.
      <B> V2<List<B>> traverseV2​(F<A,​V2<B>> f)  
      <E,​B>
      Validation<E,​List<B>>
      traverseValidation​(Semigroup<E> s, F<A,​Validation<E,​B>> f)
      Traverse this list with the given function and collect the output as a validation; use the given semigroup to reduce the errors.
      <B> B uncons​(F2<A,​List<A>,​B> cons, B nil)  
      static <A,​B>
      List<A>
      unfold​(F<B,​Option<P2<A,​B>>> f, B b)
      Unfolds across the given function starting at the given value to produce a list.
      static <A,​B>
      P2<List<A>,​List<B>>
      unzip​(List<P2<A,​B>> xs)
      Transforms a list of pairs into a list of first components and a list of second components.
      static <A,​B>
      F<List<A>,​F<List<B>,​List<P2<A,​B>>>>
      zip()
      The first-class version of the zip function.
      <B> List<P2<A,​B>> zip​(List<B> bs)
      Zips this list with the given list to produce a list of pairs.
      List<P2<A,​java.lang.Integer>> zipIndex()
      Zips this list with the index of its element as a pair.
      static <A,​B,​C>
      F<List<A>,​F<List<B>,​F<F<A,​F<B,​C>>,​List<C>>>>
      zipWith()
      Provides a first-class version of zipWith
      <B,​C>
      List<C>
      zipWith​(List<B> bs, F<A,​F<B,​C>> f)
      Zips this list with the given list using the given function to produce a new list.
      <B,​C>
      List<C>
      zipWith​(List<B> bs, F2<A,​B,​C> f)
      Zips this list with the given list using the given function to produce a new list.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • List

        private List()
    • Method Detail

      • iterator

        public final java.util.Iterator<A> iterator()
        Returns an iterator for this list. This method exists to permit the use in a for-each loop.
        Specified by:
        iterator in interface java.lang.Iterable<A>
        Returns:
        A iterator for this list.
      • head

        public abstract A head()
        The first element of the linked list or fails for the empty list.
        Returns:
        The first element of the linked list or fails for the empty list.
      • tail

        public abstract List<A> tail()
        The list without the first element or fails for the empty list.
        Returns:
        The list without the first element or fails for the empty list.
      • length

        public final int length()
        The length of this list.
        Returns:
        The length of this list.
      • isEmpty

        public final boolean isEmpty()
        Returns true if this list is empty, false otherwise.
        Returns:
        true if this list is empty, false otherwise.
      • isNotEmpty

        public final boolean isNotEmpty()
        Returns false if this list is empty, true otherwise.
        Returns:
        false if this list is empty, true otherwise.
      • uncons

        public final <B> B uncons​(F2<A,​List<A>,​B> cons,
                                  B nil)
      • orHead

        public final A orHead​(F0<A> a)
        Returns the head of this list if there is one or the given argument if this list is empty.
        Parameters:
        a - The argument to return if this list is empty.
        Returns:
        The head of this list if there is one or the given argument if this list is empty.
      • orTail

        public final List<A> orTail​(F0<List<A>> as)
        Returns the tail of this list if there is one or the given argument if this list is empty.
        Parameters:
        as - The argument to return if this list is empty.
        Returns:
        The tail of this list if there is one or the given argument if this list is empty.
      • headOption

        public final Option<A> headOption()
        Returns the head of the list, if any.
        Returns:
        The optional head of the list.
      • toEither

        public final <X> Either<X,​A> toEither​(F0<X> x)
        Returns an either projection of this list; the given argument in Left if empty, or the first element in Right.
        Parameters:
        x - The value to return in left if this list is empty.
        Returns:
        An either projection of this list.
      • toStream

        public final Stream<A> toStream()
        Returns a stream projection of this list.
        Returns:
        A stream projection of this list.
      • toArray

        public final Array<A> toArray()
        Returns a array projection of this list.
        Returns:
        A array projection of this list.
      • toArrayObject

        public final java.lang.Object[] toArrayObject()
      • toArray

        public final Array<A> toArray​(java.lang.Class<A[]> c)
        Returns a array projection of this list.
        Parameters:
        c - The class type of the array to return.
        Returns:
        A array projection of this list.
      • array

        public final A[] array​(java.lang.Class<A[]> c)
        Returns an array from this list.
        Parameters:
        c - The class type of the array to return.
        Returns:
        An array from this list.
      • cons

        public final List<A> cons​(A a)
        Prepends (cons) the given element to this list to product a new list.
        Parameters:
        a - The element to prepend.
        Returns:
        A new list with the given element at the head.
      • conss

        public final List<A> conss​(A a)
        Prepends (cons) the given element to this list to product a new list. This method is added to prevent conflict with overloads.
        Parameters:
        a - The element to prepend.
        Returns:
        A new list with the given element at the head.
      • map

        public final <B> List<B> map​(F<A,​B> f)
        Maps the given function across this list.
        Parameters:
        f - The function to map across this list.
        Returns:
        A new list after the given function has been applied to each element.
      • foreach

        public final Unit foreach​(F<A,​Unit> f)
        Performs a side-effect for each element of this list.
        Parameters:
        f - The side-effect to perform for the given element.
        Returns:
        The unit value.
      • foreachDoEffect

        public final void foreachDoEffect​(Effect1<A> f)
        Performs a side-effect for each element of this list.
        Parameters:
        f - The side-effect to perform for the given element.
      • filter

        public final List<A> filter​(F<A,​java.lang.Boolean> f)
        Filters elements from this list by returning only elements which produce true when the given function is applied to them.
        Parameters:
        f - The predicate function to filter on.
        Returns:
        A new list whose elements all match the given predicate.
      • removeAll

        public final List<A> removeAll​(F<A,​java.lang.Boolean> f)
        Filters elements from this list by returning only elements which produce false when the given function is applied to them.
        Parameters:
        f - The predicate function to filter on.
        Returns:
        A new list whose elements do not match the given predicate.
      • delete

        public final List<A> delete​(A a,
                                    Equal<A> e)
        Removes the first element that equals the given object. To remove all matches, use removeAll(e.eq(a))
        Parameters:
        a - The element to remove
        e - An Equals instance for the element's type.
        Returns:
        A new list whose elements do not match the given predicate.
      • takeWhile

        public final List<A> takeWhile​(F<A,​java.lang.Boolean> f)
        Returns the first elements of the head of this list that match the given predicate function.
        Parameters:
        f - The predicate function to apply on this list until it finds an element that does not hold, or the list is exhausted.
        Returns:
        The first elements of the head of this list that match the given predicate function.
      • dropWhile

        public final List<A> dropWhile​(F<A,​java.lang.Boolean> f)
        Removes elements from the head of this list that do not match the given predicate function until an element is found that does match or the list is exhausted.
        Parameters:
        f - The predicate function to apply through this list.
        Returns:
        The list whose first element does not match the given predicate function.
      • span

        public final P2<List<A>,​List<A>> span​(F<A,​java.lang.Boolean> p)
        Returns a tuple where the first element is the longest prefix of this list that satisfies the given predicate and the second element is the remainder of the list.
        Parameters:
        p - A predicate to be satisfied by a prefix of this list.
        Returns:
        A tuple where the first element is the longest prefix of this list that satisfies the given predicate and the second element is the remainder of the list.
      • breakk

        public final P2<List<A>,​List<A>> breakk​(F<A,​java.lang.Boolean> p)
        Returns a tuple where the first element is the longest prefix of this list that does not satisfy the given predicate and the second element is the remainder of the list.
        Parameters:
        p - A predicate for an element to not satisfy by a prefix of this list.
        Returns:
        A tuple where the first element is the longest prefix of this list that does not satisfy the given predicate and the second element is the remainder of the list.
      • group

        public final List<List<A>> group​(Equal<A> e)
        Groups elements according to the given equality implementation by longest sequence of equal elements.
        Parameters:
        e - The equality implementation for the elements.
        Returns:
        A list of grouped elements.
      • bind

        public final <B> List<B> bind​(F<A,​List<B>> f)
        Binds the given function across each element of this list with a final join.
        Parameters:
        f - The function to apply to each element of this list.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C> List<C> bind​(List<B> lb,
                                              F<A,​F<B,​C>> f)
        Binds the given function across each element of this list and the given list with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given list.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C> List<C> bind​(List<B> lb,
                                              F2<A,​B,​C> f)
        Binds the given function across each element of this list and the given list with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given list.
        Returns:
        A new list after performing the map, then final join.
      • liftM2

        public static <A,​B,​C> F<List<A>,​F<List<B>,​List<C>>> liftM2​(F<A,​F<B,​C>> f)
        Promotes the given function of arity-2 to a function on lists.
        Parameters:
        f - The function to promote to a function on lists.
        Returns:
        The given function, promoted to operate on lists.
      • bind

        public final <B,​C,​D> List<D> bind​(List<B> lb,
                                                      List<C> lc,
                                                      F<A,​F<B,​F<C,​D>>> f)
        Binds the given function across each element of this list and the given lists with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        lc - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given lists.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E> List<E> bind​(List<B> lb,
                                                              List<C> lc,
                                                              List<D> ld,
                                                              F<A,​F<B,​F<C,​F<D,​E>>>> f)
        Binds the given function across each element of this list and the given lists with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        lc - A given list to bind the given function with.
        ld - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given lists.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$> List<F$> bind​(List<B> lb,
                                                                        List<C> lc,
                                                                        List<D> ld,
                                                                        List<E> le,
                                                                        F<A,​F<B,​F<C,​F<D,​F<E,​F$>>>>> f)
        Binds the given function across each element of this list and the given lists with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        lc - A given list to bind the given function with.
        ld - A given list to bind the given function with.
        le - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given lists.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$,​G> List<G> bind​(List<B> lb,
                                                                               List<C> lc,
                                                                               List<D> ld,
                                                                               List<E> le,
                                                                               List<F$> lf,
                                                                               F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​G>>>>>> f)
        Binds the given function across each element of this list and the given lists with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        lc - A given list to bind the given function with.
        ld - A given list to bind the given function with.
        le - A given list to bind the given function with.
        lf - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given lists.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$,​G,​H> List<H> bind​(List<B> lb,
                                                                                       List<C> lc,
                                                                                       List<D> ld,
                                                                                       List<E> le,
                                                                                       List<F$> lf,
                                                                                       List<G> lg,
                                                                                       F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​H>>>>>>> f)
        Binds the given function across each element of this list and the given lists with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        lc - A given list to bind the given function with.
        ld - A given list to bind the given function with.
        le - A given list to bind the given function with.
        lf - A given list to bind the given function with.
        lg - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given lists.
        Returns:
        A new list after performing the map, then final join.
      • bind

        public final <B,​C,​D,​E,​F$,​G,​H,​I> List<I> bind​(List<B> lb,
                                                                                               List<C> lc,
                                                                                               List<D> ld,
                                                                                               List<E> le,
                                                                                               List<F$> lf,
                                                                                               List<G> lg,
                                                                                               List<H> lh,
                                                                                               F<A,​F<B,​F<C,​F<D,​F<E,​F<F$,​F<G,​F<H,​I>>>>>>>> f)
        Binds the given function across each element of this list and the given lists with a final join.
        Parameters:
        lb - A given list to bind the given function with.
        lc - A given list to bind the given function with.
        ld - A given list to bind the given function with.
        le - A given list to bind the given function with.
        lf - A given list to bind the given function with.
        lg - A given list to bind the given function with.
        lh - A given list to bind the given function with.
        f - The function to apply to each element of this list and the given lists.
        Returns:
        A new list after performing the map, then final join.
      • sequence

        public final <B> List<B> sequence​(List<B> bs)
        Performs a bind across each list element, but ignores the element value each time.
        Parameters:
        bs - The list to apply in the final join.
        Returns:
        A new list after the final join.
      • sequenceEither

        public static final <L,​B> Either<L,​List<B>> sequenceEither​(List<Either<L,​B>> list)
        Sequence the given list and collect the output on the right side of an either.
        Type Parameters:
        B - the type of the right value
        L - the type of the left value
        Parameters:
        list - the given list
        Returns:
        the either
      • sequenceEitherLeft

        public static final <R,​B> Either<List<B>,​R> sequenceEitherLeft​(List<Either<B,​R>> list)
        Sequence the given list and collect the output on the left side of an either.
        Type Parameters:
        R - the type of the right value
        B - the type of the left value
        Parameters:
        list - the given list
        Returns:
        the either
      • sequenceEitherRight

        public static final <L,​B> Either<L,​List<B>> sequenceEitherRight​(List<Either<L,​B>> list)
        Sequence the given list and collect the output on the right side of an either.
        Type Parameters:
        B - the type of the right value
        L - the type of the left value
        Parameters:
        list - the given list
        Returns:
        the either
      • sequenceF

        public static final <C,​B> F<C,​List<B>> sequenceF​(List<F<C,​B>> list)
        Sequence the given list and collect the output as a function.
        Type Parameters:
        C - the type of the input value
        B - the type of the output value
        Parameters:
        list - the given list
        Returns:
        the either
      • sequenceIO

        public static final <B> IO<List<B>> sequenceIO​(List<IO<B>> list)
        Sequence the given list and collect the output as an IO.
        Type Parameters:
        B - the type of the IO value
        Parameters:
        list - the given list
        Returns:
        the IO
      • sequenceList

        public static final <B> List<List<B>> sequenceList​(List<List<B>> list)
        Sequence the given list and collect the output as an list.
        Type Parameters:
        B - the type of the list value
        Parameters:
        list - the given list
        Returns:
        the list
      • sequenceOption

        public static final <B> Option<List<B>> sequenceOption​(List<Option<B>> list)
        Sequence the given list and collect the output as an list.
        Type Parameters:
        B - the type of the list value
        Parameters:
        list - the given list
        Returns:
        the list
      • sequenceP1

        public static final <B> P1<List<B>> sequenceP1​(List<P1<B>> list)
        Sequence the given list and collect the output as a P1.
        Type Parameters:
        B - the type of the P1 value
        Parameters:
        list - the given list
        Returns:
        the P1
      • sequenceSeq

        public static final <B> Seq<List<B>> sequenceSeq​(List<Seq<B>> list)
        Sequence the given list and collect the output as a seq.
        Type Parameters:
        B - the type of the seq value
        Parameters:
        list - the given list
        Returns:
        the seq
      • sequenceSet

        public static final <B> Set<List<B>> sequenceSet​(Ord<B> ord,
                                                         List<Set<B>> list)
        Sequence the given list and collect the output as a set; use the given ord to order the set.
        Type Parameters:
        B - the type of the set value
        Parameters:
        ord - the given ord
        list - the given list
        Returns:
        the either
      • sequenceStream

        public static final <B> Stream<List<B>> sequenceStream​(List<Stream<B>> list)
        Sequence the given list and collect the output as a stream.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        list - the given list
        Returns:
        the stream
      • sequenceTrampoline

        public static final <B> Trampoline<List<B>> sequenceTrampoline​(List<Trampoline<B>> list)
        Sequence the given list and collect the output as a trampoline.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        list - the given trampoline
        Returns:
        the stream
      • sequenceValidation

        public static final <E,​B> Validation<E,​List<B>> sequenceValidation​(Semigroup<E> semigroup,
                                                                                       List<Validation<E,​B>> list)
        Sequence the given list and collect the output as a validation; use the given semigroup to reduce the errors.
        Type Parameters:
        E - the type of the failure value
        B - the type of the success value
        Parameters:
        semigroup - the given semigroup
        list - the given list
        Returns:
        the validation
      • traverseEither

        public final <B,​E> Either<E,​List<B>> traverseEither​(F<A,​Either<E,​B>> f)
        Traverse through the List with given function.
        Parameters:
        f - The function that produces Either value.
        Returns:
        error in left or f mapped list in right.
      • traverseEitherLeft

        public final <R,​B> Either<List<B>,​R> traverseEitherLeft​(F<A,​Either<B,​R>> f)
        Traverse this list with the given function and collect the output on the left side of an either.
        Type Parameters:
        R - the type of the left value
        B - the type of the right value
        Parameters:
        f - the given function
        Returns:
        the either
      • traverseEitherRight

        public final <L,​B> Either<L,​List<B>> traverseEitherRight​(F<A,​Either<L,​B>> f)
        Traverse this list with the given function and collect the output on the right side of an either.
        Type Parameters:
        L - the type of the left value
        B - the type of the right value
        Parameters:
        f - the given function
        Returns:
        the either
      • traverseF

        public final <C,​B> F<C,​List<B>> traverseF​(F<A,​F<C,​B>> f)
        Traverse this list with the given function and collect the output as a function.
        Type Parameters:
        C - the type of the input value
        B - the type of the output value
        Parameters:
        f - the given function
        Returns:
        the function
      • traverseIO

        public final <B> IO<List<B>> traverseIO​(F<A,​IO<B>> f)
        Traverse this list with the given function and collect the output as an IO.
        Type Parameters:
        B - the type of the IO value
        Parameters:
        f - the given function
        Returns:
        the IO
      • traverseList

        public final <B> List<List<B>> traverseList​(F<A,​List<B>> f)
        Traverse this list with the given function and collect the output as a list.
        Type Parameters:
        B - the type of the list value
        Parameters:
        f - the given function
        Returns:
        the list
      • traverseOption

        public final <B> Option<List<B>> traverseOption​(F<A,​Option<B>> f)
        Traverses through the List with the given function
        Parameters:
        f - The function that produces Option value
        Returns:
        none if applying f returns none to any element of the list or f mapped list in some .
      • traverseP1

        public final <B> P1<List<B>> traverseP1​(F<A,​P1<B>> f)
        Traverse this list with the given function and collect the output as a p1.
        Type Parameters:
        B - the type of the p1 value
        Parameters:
        f - the given function
        Returns:
        the p1
      • traverseSeq

        public final <B> Seq<List<B>> traverseSeq​(F<A,​Seq<B>> f)
        Traverse this list with the given function and collect the output as a seq.
        Type Parameters:
        B - the type of the seq value
        Parameters:
        f - the given function
        Returns:
        the seq
      • traverseSet

        public final <B> Set<List<B>> traverseSet​(Ord<B> ord,
                                                  F<A,​Set<B>> f)
        Traverse this list with the given function and collect the output as a set; use the given ord to order the set.
        Type Parameters:
        B - the type of the set value
        Parameters:
        ord - the given ord
        f - the given function
        Returns:
        the set
      • traverseStream

        public final <B> Stream<List<B>> traverseStream​(F<A,​Stream<B>> f)
        Traverse this list with the given function and collect the output as a stream.
        Type Parameters:
        B - the type of the stream value
        Parameters:
        f - the given function
        Returns:
        the stream
      • traverseTrampoline

        public final <B> Trampoline<List<B>> traverseTrampoline​(F<A,​Trampoline<B>> f)
        Traverse this list with the given function and collect the output as a trampoline.
        Type Parameters:
        B - the type of the trampoline value
        Parameters:
        f - the given function
        Returns:
        the trampoline
      • traverseValidation

        public final <E,​B> Validation<E,​List<B>> traverseValidation​(Semigroup<E> s,
                                                                                F<A,​Validation<E,​B>> f)
        Traverse this list with the given function and collect the output as a validation; use the given semigroup to reduce the errors.
        Type Parameters:
        E - the type of the failure value
        B - the type of the success value
        Parameters:
        s - the given semigroup
        f - the given function
        Returns:
        the validation
      • traverseV2

        public final <B> V2<List<B>> traverseV2​(F<A,​V2<B>> f)
      • apply

        public final <B> List<B> apply​(List<F<A,​B>> lf)
        Performs function application within a list (applicative functor pattern).
        Parameters:
        lf - The list of functions to apply.
        Returns:
        A new list after applying the given list of functions through this list.
      • append

        public final List<A> append​(List<A> as)
        Appends the given list to this list.
        Parameters:
        as - The list to append to this one.
        Returns:
        A new list that has appended the given list.
      • foldRight

        public final <B> B foldRight​(F<A,​F<B,​B>> f,
                                     B b)
        Performs a right-fold reduction across this list.
        Parameters:
        f - The function to apply on each element of the list.
        b - The beginning value to start the application from.
        Returns:
        The final result after the right-fold reduction.
      • foldRight

        public final <B> B foldRight​(F2<A,​B,​B> f,
                                     B b)
        Performs a right-fold reduction across this list. This function uses O(length) stack space.
        Parameters:
        f - The function to apply on each element of the list.
        b - The beginning value to start the application from.
        Returns:
        The final result after the right-fold reduction.
      • foldRightC

        public final <B> Trampoline<B> foldRightC​(F2<A,​B,​B> f,
                                                  B b)
        Performs a right-fold reduction across this list in O(1) stack space.
        Parameters:
        f - The function to apply on each element of the list.
        b - The beginning value to start the application from.
        Returns:
        A Trampoline containing the final result after the right-fold reduction.
      • foldLeft

        public final <B> B foldLeft​(F<B,​F<A,​B>> f,
                                    B b)
        Performs a left-fold reduction across this list. This function runs in constant space.
        Parameters:
        f - The function to apply on each element of the list.
        b - The beginning value to start the application from.
        Returns:
        The final result after the left-fold reduction.
      • foldLeft

        public final <B> B foldLeft​(F2<B,​A,​B> f,
                                    B b)
        Performs a left-fold reduction across this list. This function runs in constant space.
        Parameters:
        f - The function to apply on each element of the list.
        b - The beginning value to start the application from.
        Returns:
        The final result after the left-fold reduction.
      • foldLeft1

        public final A foldLeft1​(F2<A,​A,​A> f)
        Takes the first 2 elements of the list and applies the function to them, then applies the function to the result and the third element and so on.
        Parameters:
        f - The function to apply on each element of the list.
        Returns:
        The final result after the left-fold reduction.
      • foldLeft1

        public final A foldLeft1​(F<A,​F<A,​A>> f)
        Takes the first 2 elements of the list and applies the function to them, then applies the function to the result and the third element and so on.
        Parameters:
        f - The function to apply on each element of the list.
        Returns:
        The final result after the left-fold reduction.
      • reverse

        public final List<A> reverse()
        Reverse this list in constant stack space.
        Returns:
        A new list that is the reverse of this one.
      • index

        public final A index​(int i)
        Returns the element at the given index if it exists, fails otherwise.
        Parameters:
        i - The index at which to get the element to return.
        Returns:
        The element at the given index if it exists, fails otherwise.
      • take

        public final List<A> take​(int i)
        Takes the given number of elements from the head of this list if they are available.
        Parameters:
        i - The maximum number of elements to take from this list.
        Returns:
        A new list with a length the same, or less than, this list.
      • drop

        public final List<A> drop​(int i)
        Drops the given number of elements from the head of this list if they are available.
        Parameters:
        i - The number of elements to drop from the head of this list.
        Returns:
        A list with a length the same, or less than, this list.
      • splitAt

        public final P2<List<A>,​List<A>> splitAt​(int i)
        Splits this list into two lists at the given index. If the index goes out of bounds, then it is normalised so that this function never fails.
        Parameters:
        i - The index at which to split this list in two parts.
        Returns:
        A pair of lists split at the given index of this list.
      • partition

        public final List<List<A>> partition​(int n)
        Splits this list into lists of the given size. If the size of this list is not evenly divisible by the given number, the last partition will contain the remainder.
        Parameters:
        n - The size of the partitions into which to split this list.
        Returns:
        A list of sublists of this list, of at most the given size.
      • partition

        public final P2<List<A>,​List<A>> partition​(F<A,​java.lang.Boolean> f)
        Partitions the list into a tuple where the first element contains the items that satisfy the the predicate f and the second element contains the items that does not. The relative order of the elements in the returned tuple is the same as the original list.
        Parameters:
        f - Predicate function.
      • inits

        public final List<List<A>> inits()
        Returns the list of initial segments of this list, shortest first.
        Returns:
        The list of initial segments of this list, shortest first.
      • tails

        public final List<List<A>> tails()
        Returns the list of final segments of this list, longest first.
        Returns:
        The list of final segments of this list, longest first.
      • sort

        public final List<A> sort​(Ord<A> o)
        Sorts this list using the given order over elements using a merge sort algorithm.
        Parameters:
        o - The order over the elements of this list.
        Returns:
        A sorted list according to the given order.
      • zipWith

        public final <B,​C> List<C> zipWith​(List<B> bs,
                                                 F<A,​F<B,​C>> f)
        Zips this list with the given list using the given function to produce a new list. If this list and the given list have different lengths, then the longer list is normalised so this function never fails.
        Parameters:
        bs - The list to zip this list with.
        f - The function to zip this list and the given list with.
        Returns:
        A new list with a length the same as the shortest of this list and the given list.
      • zipWith

        public final <B,​C> List<C> zipWith​(List<B> bs,
                                                 F2<A,​B,​C> f)
        Zips this list with the given list using the given function to produce a new list. If this list and the given list have different lengths, then the longer list is normalised so this function never fails.
        Parameters:
        bs - The list to zip this list with.
        f - The function to zip this list and the given list with.
        Returns:
        A new list with a length the same as the shortest of this list and the given list.
      • zipWith

        public static <A,​B,​C> F<List<A>,​F<List<B>,​F<F<A,​F<B,​C>>,​List<C>>>> zipWith()
        Provides a first-class version of zipWith
        Returns:
        The first-class version of zipWith
      • zip

        public final <B> List<P2<A,​B>> zip​(List<B> bs)
        Zips this list with the given list to produce a list of pairs. If this list and the given list have different lengths, then the longer list is normalised so this function never fails.
        Parameters:
        bs - The list to zip this list with.
        Returns:
        A new list with a length the same as the shortest of this list and the given list.
      • zip

        public static <A,​B> F<List<A>,​F<List<B>,​List<P2<A,​B>>>> zip()
        The first-class version of the zip function.
        Returns:
        A function that zips the given lists to produce a list of pairs.
      • zipIndex

        public final List<P2<A,​java.lang.Integer>> zipIndex()
        Zips this list with the index of its element as a pair.
        Returns:
        A new list with the same length as this list.
      • snoc

        public final List<A> snoc​(A a)
        Appends (snoc) the given element to this list to produce a new list.
        Parameters:
        a - The element to append to this list.
        Returns:
        A new list with the given element appended.
      • forall

        public final boolean forall​(F<A,​java.lang.Boolean> f)
        Returns true if the predicate holds for all of the elements of this list, false otherwise (true for the empty list).
        Parameters:
        f - The predicate function to test on each element of this list.
        Returns:
        true if the predicate holds for all of the elements of this list, false otherwise.
      • exists

        public final boolean exists​(F<A,​java.lang.Boolean> f)
        Returns true if the predicate holds for at least one of the elements of this list, false otherwise (false for the empty list).
        Parameters:
        f - The predicate function to test on the elements of this list.
        Returns:
        true if the predicate holds for at least one of the elements of this list.
      • find

        public final Option<A> find​(F<A,​java.lang.Boolean> f)
        Finds the first occurrence of an element that matches the given predicate or no value if no elements match.
        Parameters:
        f - The predicate function to test on elements of this list.
        Returns:
        The first occurrence of an element that matches the given predicate or no value if no elements match.
      • intersperse

        public final List<A> intersperse​(A a)
        Intersperses the given argument between each element of this list.
        Parameters:
        a - The separator to intersperse in this list.
        Returns:
        A list with the given separator interspersed.
      • intercalate

        public final List<A> intercalate​(List<List<A>> as)
        Intersperses this list through the given list then joins the results.
        Parameters:
        as - The list to intersperse through.
        Returns:
        This list through the given list then joins the results.
      • nub

        public final List<A> nub()
        Removes duplicates according to object equality.
        Returns:
        A list without duplicates according to object equality.
      • nub

        public final List<A> nub​(Equal<A> eq)
        Removes duplicates according to the given equality. Warning: O(n^2).
        Parameters:
        eq - Equality over the elements.
        Returns:
        A list without duplicates.
      • nub

        public final List<A> nub​(Ord<A> o)
        Removes duplicates according to the given ordering. This function is O(n).
        Parameters:
        o - An ordering for the elements.
        Returns:
        A list without duplicates.
      • head_

        public static <A> F<List<A>,​A> head_()
        First-class head function.
        Returns:
        A function that gets the head of a given list.
      • tailOption

        public final Option<List<A>> tailOption()
        Reutrns the tail of the list, if any.
        Returns:
        The optional tail of the list.
      • tail_

        public static <A> F<List<A>,​List<A>> tail_()
        First-class tail function.
        Returns:
        A function that gets the tail of a given list.
      • minus

        public final List<A> minus​(Equal<A> eq,
                                   List<A> xs)
        Returns a new list of all the items in this list that do not appear in the given list.
        Parameters:
        eq - an equality for the items of the lists.
        xs - a list to subtract from this list.
        Returns:
        a list of all the items in this list that do not appear in the given list.
      • mapM

        public final <B,​C> F<B,​List<C>> mapM​(F<A,​F<B,​C>> f)
        Maps the given function of arity-2 across this list and returns a function that applies all the resulting functions to a given argument.
        Parameters:
        f - A function of arity-2
        Returns:
        A function that, when given an argument, applies the given function to that argument and every element in this list.
      • mapMOption

        public final <B> Option<List<B>> mapMOption​(F<A,​Option<B>> f)
        Maps the given function across this list by binding through the Option monad.
        Parameters:
        f - The function to apply through the this list.
        Returns:
        A possible list of values after binding through the Option monad.
      • mapMTrampoline

        public final <B> Trampoline<List<B>> mapMTrampoline​(F<A,​Trampoline<B>> f)
        Maps the given function across this list by binding through the Trampoline monad.
        Parameters:
        f - The function to apply through the this list.
        Returns:
        A list of values in the Trampoline monad.
      • elementIndex

        public final Option<java.lang.Integer> elementIndex​(Equal<A> e,
                                                            A a)
        Returns the index of the first element in this list which is equal (by the given equality) to the query element, or None if there is no such element.
        Parameters:
        e - An equality for this list's elements.
        a - A query element.
        Returns:
        The index of the first element in this list which is equal (by the given equality) to the query element, or None if there is no such element.
      • last

        public final A last()
        Returns the last element of this list. Undefined for the empty list.
        Returns:
        The last element of this list or throws an error if this list is empty.
      • init

        public final List<A> init()
        Returns all but the last element of this list. Undefiend for the empty list.
        Returns:
        All but the last element of this list. Undefiend for the empty list.
      • insertBy

        public final List<A> insertBy​(F<A,​F<A,​Ordering>> f,
                                      A x)
        Inserts the given element before the first element that is greater than or equal to it according to the given ordering.
        Parameters:
        f - An ordering function to compare elements.
        x - The element to insert.
        Returns:
        A new list with the given element inserted before the first element that is greater than or equal to it according to the given ordering.
      • mode

        public final A mode​(Ord<A> o)
        Returns the most common element in this list.
        Parameters:
        o - An ordering for the elements of the list.
        Returns:
        The most common element in this list.
      • groupBy

        public final <B> TreeMap<B,​List<A>> groupBy​(F<A,​B> keyFunction,
                                                          Ord<B> keyOrd)
        Groups the elements of this list by a given keyFunction into a TreeMap.
        Parameters:
        keyFunction - The function to select the keys for the map.
        keyOrd - An order for the keys of the tree map.
        Returns:
        A TreeMap containing the keys with the accumulated list of matched elements.
      • groupBy

        public final <B,​C> TreeMap<B,​List<C>> groupBy​(F<A,​B> keyFunction,
                                                                  F<A,​C> valueFunction,
                                                                  Ord<B> keyOrd)
        Groups the elements of this list by a given keyFunction into a TreeMap and transforms the matching elements with the given valueFunction. The ordering of the keys is determined by the keyOrd parameter.
        Parameters:
        keyFunction - The function to select the keys for the map.
        valueFunction - The function to apply on each matching value.
        keyOrd - An order for the keys of the tree map.
        Returns:
        A TreeMap containing the keys with the accumulated list of matched and mapped elements.
      • groupBy

        public final <B,​C> TreeMap<B,​C> groupBy​(F<A,​B> keyFunction,
                                                            F<A,​C> valueFunction,
                                                            Monoid<C> monoid,
                                                            Ord<B> keyOrd)
        Groups the elements of this list by a given keyFunction into a TreeMap and transforms the matching elements with the given valueFunction. The ordering of the keys is determined by the keyOrd parameter.
        Parameters:
        keyFunction - The function to select the keys for the map.
        valueFunction - The function to apply on each matching value.
        monoid - A monoid, which defines the accumulator for the values and the zero value.
        keyOrd - An order for the keys of the tree map.
        Returns:
        A TreeMap containing the keys with the accumulated list of matched and mapped elements.
      • groupBy

        public final <B,​C,​D> TreeMap<B,​D> groupBy​(F<A,​B> keyFunction,
                                                                    F<A,​C> valueFunction,
                                                                    D groupingIdentity,
                                                                    F2<C,​D,​D> groupingAcc,
                                                                    Ord<B> keyOrd)
        Groups the elements of this list by a given keyFunction, applies the valueFunction and accumulates the mapped values with the given grouping accumulator function on the grouping identity.
        Parameters:
        keyFunction - The function to select the keys.
        valueFunction - The function to apply on each element.
        groupingIdentity - The identity, or start value, for the grouping.
        groupingAcc - The accumulator to apply on each matching value.
        keyOrd - An order for the keys of the tree map.
        Returns:
        A TreeMap containing the keys with the accumulated result of matched and mapped elements.
      • allEqual

        public final boolean allEqual​(Equal<A> eq)
        Returns whether or not all elements in the list are equal according to the given equality test.
        Parameters:
        eq - The equality test.
        Returns:
        Whether or not all elements in the list are equal according to the given equality test.
      • isPrefixOf

        public final boolean isPrefixOf​(Equal<A> eq,
                                        List<A> xs)
      • isSuffixOf

        public final boolean isSuffixOf​(Equal<A> eq,
                                        List<A> xs)
      • length_

        public static <A> F<List<A>,​java.lang.Integer> length_()
        First-class length.
        Returns:
        A function that gets the length of a given list.
      • maximum

        public final A maximum​(Ord<A> o)
        Returns the maximum element in this list according to the given ordering.
        Parameters:
        o - An ordering for the elements of the list.
        Returns:
        The maximum element in this list according to the given ordering.
      • maximumOption

        public final Option<A> maximumOption​(Ord<A> o)
        Returns the maximum element in this list according to the given ordering.
        Parameters:
        o - An ordering for the elements of the list.
        Returns:
        The optional maximum element in this list according to the given ordering.
      • minimum

        public final A minimum​(Ord<A> o)
        Returns the minimum element in this list according to the given ordering.
        Parameters:
        o - An ordering for the elements of the list.
        Returns:
        The minimum element in this list according to the given ordering.
      • minimumOption

        public final Option<A> minimumOption​(Ord<A> o)
        Returns the minimum element in this list according to the given ordering.
        Parameters:
        o - An ordering for the elements of the list.
        Returns:
        The optional minimum element in this list according to the given ordering.
      • toJavaList

        public final java.util.List<A> toJavaList()
      • toCollection

        public final java.util.Collection<A> toCollection()
        Projects an immutable collection of this list.
        Returns:
        An immutable collection of this list.
      • list

        @SafeVarargs
        public static <A> List<A> list​(A... as)
        Constructs a list from the given elements.
        Parameters:
        as - The elements to construct a list with.
        Returns:
        A list with the given elements.
      • arrayList

        @SafeVarargs
        public static <A> List<A> arrayList​(A... as)
        Constructs a list from the given elements.
      • fromIterator

        public static <A> List<A> fromIterator​(java.util.Iterator<A> it)
        Constructs a list from the given Iterator.
      • nil

        public static <A> List<A> nil()
        Returns an empty list.
        Returns:
        An empty list.
      • cons

        public static <A> F<A,​F<List<A>,​List<A>>> cons()
        Returns a function that prepends (cons) an element to a list to produce a new list.
        Returns:
        A function that prepends (cons) an element to a list to produce a new list.
      • cons_

        public static <A> F2<A,​List<A>,​List<A>> cons_()
      • cons

        public static <A> F<A,​List<A>> cons​(List<A> tail)
        Returns a function that prepends a value to the given list.
        Parameters:
        tail - The list to prepend to.
        Returns:
        A function that prepends a value to the given list.
      • cons_

        public static <A> F<List<A>,​List<A>> cons_​(A a)
        Returns a function that prepends the given value to a list.
        Parameters:
        a - The value to prepend to a list.
        Returns:
        A function that prepends the given value to a list.
      • cons

        public static <A> List<A> cons​(A head,
                                       List<A> tail)
        Prepends the given head element to the given tail element to produce a new list.
        Parameters:
        head - The element to prepend.
        tail - The list to prepend to.
        Returns:
        The list with the given element prepended.
      • isEmpty_

        public static <A> F<List<A>,​java.lang.Boolean> isEmpty_()
        Returns a function that determines whether a given list is empty.
        Returns:
        A function that determines whether a given list is empty.
      • isNotEmpty_

        public static <A> F<List<A>,​java.lang.Boolean> isNotEmpty_()
        Returns a function that determines whether a given list is not empty.
        Returns:
        A function that determines whether a given list is not empty.
      • join

        public static <A> List<A> join​(List<List<A>> o)
        Joins the given list of lists using a bind operation.
        Parameters:
        o - The list of lists to join.
        Returns:
        A new list that is the join of the given lists.
      • join

        public static <A> F<List<List<A>>,​List<A>> join()
        A first-class version of join
        Returns:
        A function that joins a list of lists using a bind operation.
      • unfold

        public static <A,​B> List<A> unfold​(F<B,​Option<P2<A,​B>>> f,
                                                 B b)
        Unfolds across the given function starting at the given value to produce a list.
        Parameters:
        f - The function to unfold across.
        b - The start value to begin the unfold.
        Returns:
        A new list that is a result of unfolding until the function does not produce a value.
      • unzip

        public static <A,​B> P2<List<A>,​List<B>> unzip​(List<P2<A,​B>> xs)
        Transforms a list of pairs into a list of first components and a list of second components.
        Parameters:
        xs - The list of pairs to transform.sp
        Returns:
        A list of first components and a list of second components.
      • replicate

        public static <A> List<A> replicate​(int n,
                                            A a)
        Returns a list of the given value replicated the given number of times.
        Parameters:
        n - The number of times to replicate the given value.
        a - The value to replicate.
        Returns:
        A list of the given value replicated the given number of times.
      • range

        public static List<java.lang.Integer> range​(int from,
                                                    int to)
        Returns a list of integers from the given from value (inclusive) to the given to value (exclusive).
        Parameters:
        from - The minimum value for the list (inclusive).
        to - The maximum value for the list (exclusive).
        Returns:
        A list of integers from the given from value (inclusive) to the given to value (exclusive).
      • fromString

        public static List<java.lang.Character> fromString​(java.lang.String s)
        Returns a list of characters from the given string. The inverse of this function is asString(List).
        Parameters:
        s - The string to produce the list of characters from.
        Returns:
        A list of characters from the given string.
      • fromString

        public static F<java.lang.String,​List<java.lang.Character>> fromString()
        A first-class fromString.
        Returns:
        A first-class fromString.
      • asString

        public static java.lang.String asString​(List<java.lang.Character> cs)
        Returns a string from the given list of characters. The invers of this function is fromString(String).
        Parameters:
        cs - The list of characters to produce the string from.
        Returns:
        A string from the given list of characters.
      • asString

        public static F<List<java.lang.Character>,​java.lang.String> asString()
        A first-class asString.
        Returns:
        A first-class asString.
      • single

        public static <A> List<A> single​(A a)
        Returns a list of one element containing the given value.
        Parameters:
        a - The value for the head of the returned list.
        Returns:
        A list of one element containing the given value.
      • iterateWhile

        public static <A> List<A> iterateWhile​(F<A,​A> f,
                                               F<A,​java.lang.Boolean> p,
                                               A a)
        Creates a list where the first item is calculated by applying the function on the third argument, the second item by applying the function on the previous result and so on.
        Parameters:
        f - The function to iterate with.
        p - The predicate which must be true for the next item in order to continue the iteration.
        a - The input to the first iteration.
        Returns:
        A list where the first item is calculated by applying the function on the third argument, the second item by applying the function on the previous result and so on.
      • lookup

        public static <A,​B> Option<B> lookup​(Equal<A> e,
                                                   List<P2<A,​B>> x,
                                                   A a)
        Returns an associated value with the given key in the list of pairs.
        Parameters:
        e - The test for equality on keys.
        x - The list of pairs to search.
        a - The key value to find the associated value of.
        Returns:
        An associated value with the given key in the list of pairs.
      • bind_

        public static <A,​B> F<F<A,​List<B>>,​F<List<A>,​List<B>>> bind_()
        Provides a first-class version of bind()
        Returns:
        The bind function for lists.
      • map_

        public static <A,​B> F<F<A,​B>,​F<List<A>,​List<B>>> map_()
        Provides a first-class version of map()
        Returns:
        The map function for lists.
      • sequence_

        public static <A,​B> F<B,​List<A>> sequence_​(List<F<B,​A>> fs)
        Turn a list of functions into a function returning a list.
        Parameters:
        fs - The list of functions to sequence into a single function that returns a list.
        Returns:
        A function that, when given an argument, applies all the functions in the given list to it and returns a list of the results.
      • foldLeft

        public static <A,​B> F<F<B,​F<A,​B>>,​F<B,​F<List<A>,​B>>> foldLeft()
        Provides a first-class version of foldLeft.
        Returns:
        The left fold function for lists.
      • take

        public static <A> F<java.lang.Integer,​F<List<A>,​List<A>>> take()
        Provides a first-class version of take.
        Returns:
        First-class version of take.
      • iterableList

        public static <A> List<A> iterableList​(java.lang.Iterable<A> i)
        Takes the given iterable to a list.
        Parameters:
        i - The iterable to take to a list.
        Returns:
        A list from the given iterable.
      • iteratorList

        public static <A> List<A> iteratorList​(java.util.Iterator<A> it)
        Constructs a list from the given Iterator.
      • equals

        public final boolean equals​(java.lang.Object obj)
        Perform an equality test on this list which delegates to the .equals() method of the member instances. This is implemented with Equal.listEqual using the anyEqual rule.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other object to check for equality against.
        Returns:
        true if this list is equal to the provided argument
      • hashCode

        public final int hashCode()
        Compute the hash code from this list as a function of the hash codes of its members. Delegates to Hash.listHash, using the anyHash() rule, which uses the hash codes of the contents.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code for this list.
      • toString

        public final java.lang.String toString()
        Obtain a string representation of this list using the toString implementations of the members. Uses Show.listShow with F2 argument and may not be very performant.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of the list
      • isSingle

        public final boolean isSingle()
        True if and only if the list has one element. Runs in constant time.