Lists { public static <X, Y> Y foldLeft(Y initial, List<X> inputList, Aggregator<? super X, Y> op) { if (null == inputList) { return initial; } Y next = initial; for (X val : inputList) { next = op.eval(val, next); } return next; } private  Lists(); static Y foldLeft(Y initial, List<X> inputList, Aggregator<? super X, Y> op); static Y foldRight(Y initial, List<X> inputList, Aggregator<? super X, Y> op); static List<Y> map(List<X> inputs, Func<? super X, ? extends Y> mapper); @SuppressWarnings("unchecked") static X[] toArray(List<X> inputs, Class<X> klazz); static List<X> distinct(List<X> inputs);  }
@Test public void testFoldLeft() { List<String> inputs = new ArrayList<String>(); inputs.add("a"); inputs.add("b"); inputs.add("c"); String stringified = Lists.foldLeft(new StringBuilder(), inputs, new Lists.Aggregator<String, StringBuilder>() { @Override public StringBuilder eval(String in, StringBuilder out) { if (0 != out.length()) { out.append(","); } out.append(in); return out; } }).toString(); assertEquals("a,b,c", stringified); }