Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.data
Class Seq<A>

java.lang.Object
  extended by fj.data.Seq<A>

public final class Seq<A>
extends Object

Provides an immutable finite sequence, implemented as a finger tree. This structure gives O(1) access to the head and tail, as well as O(log n) random access and concatenation of sequences.


Method Summary
 Seq<A> append(Seq<A> as)
          Appends the given sequence to this sequence.
 Seq<A> cons(A a)
          Inserts the given element at the front of this sequence.
static
<A> Seq<A>
empty()
          The empty sequence.
 A index(int i)
          Returns the element at the given index.
 boolean isEmpty()
          Checks if this is the empty sequence.
 int length()
          Returns the number of elements in this sequence.
static
<A> Seq<A>
single(A a)
          A singleton sequence.
 Seq<A> snoc(A a)
          Inserts the given element at the end of this sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

empty

public static <A> Seq<A> empty()
The empty sequence.

Returns:
A sequence with no elements.

single

public static <A> Seq<A> single(A a)
A singleton sequence.

Parameters:
a - The single element in the sequence.
Returns:
A new sequence with the given element in it.

cons

public Seq<A> cons(A a)
Inserts the given element at the front of this sequence.

Parameters:
a - An element to insert at the front of this sequence.
Returns:
A new sequence with the given element at the front.

snoc

public Seq<A> snoc(A a)
Inserts the given element at the end of this sequence.

Parameters:
a - An element to insert at the end of this sequence.
Returns:
A new sequence with the given element at the end.

append

public Seq<A> append(Seq<A> as)
Appends the given sequence to this sequence.

Parameters:
as - A sequence to append to this one.
Returns:
A new sequence with the given sequence appended to this one.

isEmpty

public boolean isEmpty()
Checks if this is the empty sequence.

Returns:
True if this sequence is empty, otherwise false.

length

public int length()
Returns the number of elements in this sequence.

Returns:
the number of elements in this sequence.

index

public A index(int i)
Returns the element at the given index.

Parameters:
i - The index of the element to return.
Returns:
The element at the given index, or throws an error if the index is out of bounds.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.