edu.rice.cs.plt.collect
Class ConsVisitor<T,Ret>

java.lang.Object
  extended by edu.rice.cs.plt.collect.ConsVisitor<T,Ret>
All Implemented Interfaces:
Lambda<ConsList<? extends T>,Ret>

public abstract class ConsVisitor<T,Ret>
extends java.lang.Object
implements Lambda<ConsList<? extends T>,Ret>

A visitor for ConsLists. Implementations handle the two list variants: ConsList.Empty and ConsList.Nonempty. For convenience, visitors may also be treated as Lambdas -- the value method is implemented to apply the visitor. A number of standard list visitors are also provided, either as static fields or static methods.


Constructor Summary
ConsVisitor()
           
 
Method Summary
static
<T> ConsVisitor<T,ConsList<? extends T>>
append(ConsList<? extends T> rest)
          Appends the given list to the end of another list
static
<T> ConsVisitor<T,ConsList<T>>
filter(Predicate<? super T> pred)
          Filters a list to contain only those elements accepted by the given predicate
static
<T> ConsVisitor<T,T>
first()
          Attempt to access the first of the given list (throws an exception in the empty case).
abstract  Ret forEmpty()
          Handle an empty list
abstract  Ret forNonempty(T first, ConsList<? extends T> rest)
          Handle a nonempty list
static
<S,T> ConsVisitor<S,ConsList<T>>
map(Lambda<? super S,? extends T> lambda)
          Produces a new list by applying the given lambda to each of a list's elements
static
<T> ConsVisitor<T,ConsList<? extends T>>
rest()
          Attempt to access the rest of the given list (throws an exception in the empty case).
static
<T> ConsVisitor<T,ConsList<? extends T>>
reverse()
          Reverses the order of the elements in a list
 Ret value(ConsList<? extends T> list)
          Invoke list.apply(this)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConsVisitor

public ConsVisitor()
Method Detail

forEmpty

public abstract Ret forEmpty()
Handle an empty list


forNonempty

public abstract Ret forNonempty(T first,
                                ConsList<? extends T> rest)
Handle a nonempty list


value

public Ret value(ConsList<? extends T> list)
Invoke list.apply(this)

Specified by:
value in interface Lambda<ConsList<? extends T>,Ret>

first

public static final <T> ConsVisitor<T,T> first()
Attempt to access the first of the given list (throws an exception in the empty case).


rest

public static final <T> ConsVisitor<T,ConsList<? extends T>> rest()
Attempt to access the rest of the given list (throws an exception in the empty case).


reverse

public static <T> ConsVisitor<T,ConsList<? extends T>> reverse()
Reverses the order of the elements in a list


append

public static <T> ConsVisitor<T,ConsList<? extends T>> append(ConsList<? extends T> rest)
Appends the given list to the end of another list


filter

public static <T> ConsVisitor<T,ConsList<T>> filter(Predicate<? super T> pred)
Filters a list to contain only those elements accepted by the given predicate


map

public static <S,T> ConsVisitor<S,ConsList<T>> map(Lambda<? super S,? extends T> lambda)
Produces a new list by applying the given lambda to each of a list's elements