Package fj.data
Class List.Buffer<A>
- java.lang.Object
-
- fj.data.List.Buffer<A>
-
- All Implemented Interfaces:
java.lang.Iterable<A>
public static final class List.Buffer<A> extends java.lang.Object implements java.lang.Iterable<A>
A mutable, singly linked list. This structure should be used very sparingly, in favour of theimmutable singly linked list structure
.
-
-
Constructor Summary
Constructors Constructor Description Buffer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List.Buffer<A>
append(List<A> as)
Appends the given list to this buffer.private void
copy()
static <A> List.Buffer<A>
empty()
An empty buffer.static <A> List.Buffer<A>
fromList(List<A> as)
Constructs a buffer from the given list.boolean
isEmpty()
Returnstrue
if this buffer is empty,false
otherwise.static <A> List.Buffer<A>
iterableBuffer(java.lang.Iterable<A> i)
Takes the given iterable to a buffer.java.util.Iterator<A>
iterator()
Returns an iterator for this buffer.List<A>
prependToList(List<A> as)
Prepends the elements of this buffer to the given list.List.Buffer<A>
snoc(A a)
Appends (snoc) the given element to this buffer to produce a new buffer.java.util.Collection<A>
toCollection()
Projects an immutable collection of this buffer.List<A>
toList()
Returns an immutable list projection of this buffer.
-
-
-
Method Detail
-
iterator
public java.util.Iterator<A> iterator()
Returns an iterator for this buffer. This method exists to permit the use in afor
-each loop.- Specified by:
iterator
in interfacejava.lang.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()
Returnstrue
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 java.util.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(java.lang.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()
-
-