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