// functors and a list class Procedure { fun void run() { // empty } } class UnaryProcedure { fun void run(Object arg) { // empty } } class UnaryPredicate { fun int test(Object arg) { return false; } } class UnaryFunction { Object @ default; fun Object evaluate(Object arg) { return default; } } class Comparator { fun int compare(Object arg0, Object arg1) { return 0; } } class List { // TODO: static initial capacity Object @ values[]; fun int cap() { return values.cap(); } fun int size() { // TODO: count non-null refs return values.cap(); } fun void resize(int capacity) { // TODO: copy existing values Object @ ignore[capacity] @=> values; } fun Object get(int index) { return values[index]; } fun void set(int index, Object value) { value @=> values[index]; } fun void assign(Object value) { for (0 => int i; i < cap(); i++) { value @=> values[i]; } } fun void transform(UnaryFunction fn) { for (0 => int i; i < cap(); i++) { fn.evaluate(values[i]) @=> values[i]; } } fun void forEach(UnaryProcedure procedure) { for (0 => int i; i < cap(); i++) { procedure.run(values[i]); } } fun void forEach(UnaryPredicate predicate, UnaryProcedure procedure) { for (0 => int i; i < cap(); i++) { if (predicate.test(values[i])) { procedure.run(values[i]); } } } // TODO: // fun List copy(); // fun List subList(int from, int to); // fun void sort(Comparator comparator); } class TestUnaryProcedure extends UnaryProcedure { fun void run(Object arg) { <<< "test", arg >>>; } } TestUnaryProcedure testProcedure; List list; Object a; Object b; 4 => list.resize; [ a, b ] @=> list.values; <<< "cap =", list.cap(), "size =", list.size() >>>; list.forEach(testProcedure); 1::second => now;