[all packages] [package net.sf.pizzacompiler.lang] [class hierarchy] [index]

public class net.sf.pizzacompiler.lang.List<A>

(source file: /home/enno/source/tmp/pizza/main/src/net/sf/pizzacompiler/lang/List.pizza)
java.lang.Object
   |
   +----net.sf.pizzacompiler.lang.List<A>

The pure class interface.
public class List<A>
  implements java.io.Serializable
A class for immutable lists.

Sample list construction for a list of strings:

  import pizza.lang.List;
  import pizza.lang.List.*; // imports case constructors of the list class
  ...
  List<String> list = Cons("element 1", Nil);
  list = Cons("element 2", Cons("element 3", list));

  for (List<String> now=list; now != Nil; now = now.tail()) {
    System.out.println(now.head());
  }
  
Results:
  element 2
  element 3
  element 1
  

Parameters:
A - type of the elements in the list
See also:
ListBuffer

Constuctor Index

O Cons(A, List<A>)
Construct list element.
O Nil
Empty list case.

Methods

O at(int)
Returns the element at position `n' in this list.
O bind((A) -> List<B>)
Apply `f' to each element of this list and concatenate the (list-valued) results in a new
O concat(List<A>)
Returns the result of appending list `ys' to this list as a new list.
O concat(A)
Returns the result of appending element `y' to this list as a new list.
O concatenate(List<List<A>>)
Concatenate all element lists of `xss'.
O cons(A, A, A)
Constructs a new list out of the three elements.
O cons(A, A)
Constructs a new list out of the two elements.
O cons(A)
Constructs a new list out of the element.
O cons(A, A, A, A, A, A)
Constructs a new list out of the six elements.
O cons(A, A, A, A, A, A, A, A, A, A)
Constructs a new list out of the ten elements.
O cons(A, A, A, A, A, A, A, A, A)
Constructs a new list out of the nine elements.
O cons(A, A, A, A, A, A, A, A)
Constructs a new list out of the eight elements.
O cons(A, A, A, A, A, A, A)
Constructs a new list out of the seven elements.
O cons(A, A, A, A, A)
Constructs a new list out of the five elements.
O cons(A, A, A, A)
Constructs a new list out of the four elements.
O cons()
Returns an empty list of type A..
O contains(A)
Does this list contain element `y'?
O copy(A[], int)
Copys the list in an array starting at an offset.
O copy(A[])
Copys the list in an array.
O diff(A)
Returns the list without the element `y'
O diff(List<A>)
This list without the elements in `ys'
O drop(int)
The list without its first n elements.
O elements()
Return all elements in this list as an enumeration.
O elementsToString(String)
Returns a String representation of the elements in this list with `sep' used as a separator.
O equals(Object)
Are all elements in this list equal to another list?
O filter((A) -> boolean)
Return a list of all elements for which predicate `p' is true.
O foldl((B, A) -> B, B)
Fold left. Applys function f to all elements beginning on the left
O foldr((A, B) -> B, B)
Fold right. Applys function f to all elements beginning on the right
O forall((A) -> B)
Apply `f' to each element of this list.
O fromArray(A[])
Constructs a list out of array elements.
O hashCode()
Returns a hash code for the list.
O head()
the first element of the list.
O init()
Returns all elements except the last one.
O isEmpty()
is this list empty?
O last()
Returns the last element of this list.
O length()
return the length of the list.
O map((A) -> B)
Apply `f' to each element of this list and collect the results in a new list. This
O reverse()
Returns the elements in reverse order.
O split(int)
Splits lists into two
O tail()
the rest without the first element of the list.
O take(int)
The list consisting of the first n elements of this list.
O toString()
Returns a String representation of this list.
O zip(List<A>)
Zip two lists into a list of pairs.

Constructors

O Nil
public case Nil;
Empty list case.

O Cons

public case Cons(A head,
                 List<A> tail);
Construct list element.

Parameters:
head - the element
tail - the list

Methods

O isEmpty
public boolean isEmpty();
is this list empty?

O length

public int length();
return the length of the list.

Returns:
count of elements in the list

O head

public A head();
the first element of the list.

Returns:
the first element in the list

O tail

public List<A> tail();
the rest without the first element of the list.

O take

public List<A> take(int n);
The list consisting of the first n elements of this list.

Parameters:
n - take the first n elements

O drop

public List<A> drop(int n);
The list without its first n elements.

Parameters:
n - drop the first n elements

O split

public Pair<List<A>, List<A>> split(int n);
Splits lists into two. The first part of the results is a list which consists of the first `n' elements of this list. The second part is a list containing all remaining elements. @law split(n, xs) = Pair.Pair(take(n, xs), drop(n, xs))

O at

public A at(int n);
Returns the element at position `n' in this list.

O last

public A last();
Returns the last element of this list.

O init

public List<A> init();
Returns all elements except the last one.

O reverse

public List<A> reverse();
Returns the elements in reverse order.

O concat

public List<A> concat(A y);
Returns the result of appending element `y' to this list as a new list.

O concat

public List<A> concat(List<A> ys);
Returns the result of appending list `ys' to this list as a new list.

O concatenate

public static <A> List<A> concatenate(List<List<A>> xss);
Concatenate all element lists of `xss'.

Parameters:
xss - a list of lists of type A

O forall

public <B> void forall((A) -> B f);
Apply `f' to each element of this list.
 void myPrint(String s)
 { System.out.println(s); }
     ...
 list.forall(myPrint);
 

O map

public <B> List<B> map((A) -> B f);
Apply `f' to each element of this list and collect the results in a new list. This example creates a new list where all elements have the double value as in the given list:
   int myTwoTimes(int i)
   { return i*2; }
   ...
   List twoTimesList = list.map(myTwoTimes);
   

O bind

public <B> List<B> bind((A) -> List<B> f);
Apply `f' to each element of this list and concatenate the (list-valued) results in a new list. This example creates a new list where all elements are so often in that list as their value says:
   List myTwoTimes(int i)
   { 
     List myList = Nil;
     for (int a = 0; a < i; a++)
       myList = Cons(i, myList);
     return myList; 
   }
   ...
   List twoTimesList = list.bind(myTwoTimes);
   

See also:
map, forall

O filter

public List<A> filter((A) -> boolean p);
Return a list of all elements for which predicate `p' is true.

O foldl

public <B> B foldl((B, A) -> B f,
                   B z);
Fold left. Applys function f to all elements beginning on the left.
   String plus(String a, char b)
   {
   return a + b;
   }

   List list = List.cons('1', '2', '3', '4');
   System.out.println( list.foldl(plus, "List!") );
   
Returns: List!1234
@law List.cons(x1,...,xN).foldl(OP, z) = (...(z OP x1) OP ... ) OP xN

Parameters:
f - the function to apply
z - the neutral element

O foldr

public <B> B foldr((A, B) -> B f,
                   B z);
Fold right. Applys function f to all elements beginning on the right.
   static String plus(char b, String a)
   {
   return b + a;
   }

   List list = List.cons('1', '2', '3', '4');
   System.out.println(list.foldr(plus, "List!"));
   
Returns: 1234List!
@law List.cons(x1,...,xN).foldr(OP, z) = x1 OP (... OP (xN OP z)...)

Parameters:
f - the function to apply
z - the neutral element

O contains

public boolean contains(A y);
Does this list contain element `y'?

O diff

public List<A> diff(List<A> ys);
This list without the elements in `ys'. Each element is removed at most once.

O diff

public List<A> diff(A y);
Returns the list without the element `y'. The element `y' is removed at most once.

O hashCode

public int hashCode();
Returns a hash code for the list.

Overrides:
hashCode in class Object

O equals

public boolean equals(Object other);
Are all elements in this list equal to another list?

Parameters:
other - the list to compare with
Returns:
true if all elements are equal to all elements in other
Overrides:
equals in class Object

O toString

public String toString();
Returns a String representation of this list.

Overrides:
toString in class Object

O elementsToString

public String elementsToString(String sep);
Returns a String representation of the elements in this list with `sep' used as a separator.

O elements

public Enumeration<A> elements();
Return all elements in this list as an enumeration.

O zip

public List<Pair<A, A>> zip(List<A> ys);
Zip two lists into a list of pairs.

O fromArray

public static <A> List<A> fromArray(A[] elems);
Constructs a list out of array elements.

Returns:
a list of the elements of array `elems'

O copy

public A[] copy(A[] elems);
Copys the list in an array.

Parameters:
elems - the array to copy into
Returns:
the array elems with the list elements in it

O copy

public A[] copy(A[] elems,
                int offset);
Copys the list in an array starting at an offset.

Parameters:
elems - the array to copy into
offset - the start offset in the array
Returns:
the array elems with the list elements in it

O cons

public static <A> List<A> cons();
Returns an empty list of type A..

O cons

public static <A> List<A> cons(A x1);
Constructs a new list out of the element.

O cons

public static <A> List<A> cons(A x1,
                               A x2);
Constructs a new list out of the two elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3);
Constructs a new list out of the three elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4);
Constructs a new list out of the four elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4,
                               A x5);
Constructs a new list out of the five elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4,
                               A x5,
                               A x6);
Constructs a new list out of the six elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4,
                               A x5,
                               A x6,
                               A x7);
Constructs a new list out of the seven elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4,
                               A x5,
                               A x6,
                               A x7,
                               A x8);
Constructs a new list out of the eight elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4,
                               A x5,
                               A x6,
                               A x7,
                               A x8,
                               A x9);
Constructs a new list out of the nine elements.

O cons

public static <A> List<A> cons(A x1,
                               A x2,
                               A x3,
                               A x4,
                               A x5,
                               A x6,
                               A x7,
                               A x8,
                               A x9,
                               A x10);
Constructs a new list out of the ten elements.


[all packages] [package net.sf.pizzacompiler.lang] [class hierarchy] [index]
net.sf.pizzacompiler.lang.List.html