public void testListArithmetic() {
List<List> numLists = new ArrayList<List>();
numLists.add(Arrays.asList(1, 2, 3));
numLists.add(Arrays.asList(10, 20, 30));
assertEquals(Arrays.asList(6, 60), collect(numLists, new Closure<Integer>(null) {
public Integer doCall(Integer a, Integer b, Integer c) {
return a + b + c;
}
}));
Closure<Integer> arithmeticClosure = new Closure<Integer>(null) {
public Integer doCall(Integer a, Integer b, Integer c) {
return a * b + c;
}
};
Closure<Integer> tensAndUnits = arithmeticClosure.curry(10);
assertEquals(35, (int) tensAndUnits.call(3, 5));
tensAndUnits = arithmeticClosure.ncurry(0, 10);
assertEquals(35, (int) tensAndUnits.call(3, 5));
tensAndUnits = arithmeticClosure.ncurry(1, 10);
assertEquals(35, (int) tensAndUnits.call(3, 5));
Closure<Integer> timesPlus5 = arithmeticClosure.rcurry(5);
assertEquals(35, (int) timesPlus5.call(15, 2));
timesPlus5 = arithmeticClosure.ncurry(2, 5);
assertEquals(35, (int) timesPlus5.call(15, 2));
}