Package fj.data

Class List.Buffer<A>

java.lang.Object
fj.data.List.Buffer<A>
All Implemented Interfaces:
Iterable<A>
Enclosing class:
List<A>

public static final class List.Buffer<A> extends Object implements Iterable<A>
A mutable, singly linked list. This structure should be used very sparingly, in favour of the immutable singly linked list structure.
  • Field Details

    • start

      private List<A> start
    • tail

      private List.Cons<A> tail
    • exported

      private boolean exported
  • Constructor Details

    • Buffer

      public Buffer()
  • Method Details

    • iterator

      public Iterator<A> iterator()
      Returns an iterator for this buffer. This method exists to permit the use in a for-each loop.
      Specified by:
      iterator in interface Iterable<A>
      Returns:
      A iterator for this buffer.
    • snoc

      public List.Buffer<A> snoc(A a)
      Appends (snoc) the given element to this buffer to produce a new buffer.
      Parameters:
      a - The element to append to this buffer.
      Returns:
      This buffer.
    • append

      public List.Buffer<A> append(List<A> as)
      Appends the given list to this buffer.
      Parameters:
      as - The list to append to this buffer.
      Returns:
      This buffer.
    • prependToList

      public List<A> prependToList(List<A> as)
      Prepends the elements of this buffer to the given list.
      Parameters:
      as - the list to which elements are prepended.
    • isEmpty

      public boolean isEmpty()
      Returns true if this buffer is empty, false otherwise.
    • toList

      public List<A> toList()
      Returns an immutable list projection of this buffer. Modifications to the underlying buffer will not be reflected in returned lists.
      Returns:
      An immutable list projection of this buffer.
    • toCollection

      public Collection<A> toCollection()
      Projects an immutable collection of this buffer.
      Returns:
      An immutable collection of this buffer.
    • empty

      public static <A> List.Buffer<A> empty()
      An empty buffer.
      Returns:
      An empty buffer.
    • fromList

      public static <A> List.Buffer<A> fromList(List<A> as)
      Constructs a buffer from the given list.
      Parameters:
      as - The list to construct a buffer with.
      Returns:
      A buffer from the given list.
    • iterableBuffer

      public static <A> List.Buffer<A> iterableBuffer(Iterable<A> i)
      Takes the given iterable to a buffer.
      Parameters:
      i - The iterable to take to a buffer.
      Returns:
      A buffer from the given iterable.
    • copy

      private void copy()