Class ConsList<E>

All Implemented Interfaces:
Iterable<E>, LinkedList<E>, List<E>, Traversable<E>, Iterable<E>
Direct Known Subclasses:
Cons, Nil

public abstract class ConsList<E> extends AbstractLinkedList<E>
ConsList is a functional LinkedList implementation that constructs a list by prepending an element to another list.

WARNING: Appending to a ConsList results in copying the entire list - always use a Builder when appending. Likewise, operations like set(int, Object) will result in copying portions of the list.

If there is any doubt as to the access patterns for using a List, use a Vector instead.

  • Field Details

  • Constructor Details

    • ConsList

      public ConsList()
  • Method Details

    • factory

      @NotNull public static <E> @NotNull BuilderFactory<E,ConsList<E>> factory()
    • empty

      public static <E> ConsList<E> empty()
    • prepend

      @NotNull public @NotNull ConsList<E> prepend(E elem)
      Description copied from interface: List
      Returns a list with the specified element prepended to the top of the list.
    • append

      @NotNull public abstract @NotNull ConsList<E> append(E elem)
      Description copied from interface: List
      Returns a list with the specified element appended to the bottom of the list.
    • iterator

      @NotNull public @NotNull Iterator<E> iterator()
    • range

      @NotNull public abstract @NotNull ConsList<E> range(int from, boolean fromInclusive, int to, boolean toInclusive)
      Description copied from interface: List
      Returns a list containing a contiguous range of elements from this list.
      Parameters:
      from - starting index for the range (zero-based)
      fromInclusive - if true, the element at the from index will be included
      to - end index for the range (zero-based)
      toInclusive - if true, the element at the to index will be included
    • tail

      @NotNull public abstract @NotNull ConsList<E> tail()
      Description copied from interface: List
      Returns a list containing all elements in the list, excluding the first element. An empty list is returned if the list is empty.
    • take

      @NotNull public abstract @NotNull ConsList<E> take(int number)
      Description copied from interface: List
      Returns a list containing the first number of elements from this list.
    • drop

      @NotNull public abstract @NotNull ConsList<E> drop(int number)
      Description copied from interface: List
      Returns a list containing all elements in this list, excluding the first number of elements.
    • set

      @NotNull public abstract @NotNull ConsList<E> set(int i, E elem)
      Description copied from interface: List
      Returns a list with the element set to the value specified at the index (zero-based).