Collections { @Deprecated public static <A, B> B foldl(Collection<A> as, B start, Function2<B, A, B> f) { B fold = start; for (A a : as) { fold = f.apply(fold, a); } return fold; } private  Collections(); @Deprecated static M map(Collection<A> as, M bs, Function<A, B> f); @Deprecated static B foldl(Collection<A> as, B start, Function2<B, A, B> f); @Deprecated static Collection<B> map(Collection<A> as, Function<A, B> f); @Deprecated static Collection<B> flatMap(Collection<A> as, Function<A, Collection<B>> f); @Deprecated static M flatMap(Collection<A> as, M bs, Function<A, Collection<B>> f); @Deprecated static Option<A> find(Collection<A> as, Predicate<A> p); @Deprecated static boolean exists(Collection<A> as, Predicate<A> p); @Deprecated static M filter(M as, Predicate<A> p); static Option<A> head(List<A> as); static String mkString(Collection<?> as, String sep); static T appendTo(T target, S as); @SafeVarargs static T appendToM(T target, S... as); @SafeVarargs static T appendToA(T target, X... as); static List<A> concat(M as, M bs); static Map<A, B> merge(Map<? extends A, ? extends B> a, Map<? extends A, ? extends B> b); static List<A> toList(Iterator<? extends A> as); static List<A> toList(Collection<A> as); @Deprecated static List<A> mkList(List<A> as); static List<A> nullToNil(List<A> as); @SafeVarargs static List<A> list(A... as); @SafeVarargs static List<A> nonNullList(A... as); @SuppressWarnings("unchecked") static List<A> nil(); @SuppressWarnings("unchecked") static List<A> nil(Class<A> type); static List<A> cons(A a, List<? extends A> as); @SafeVarargs static Set<A> set(A... as); static Set<A> toSet(List<A> as); @SafeVarargs static Map<K, V> map(Tuple<? extends K, ? extends V>... ts); @SafeVarargs static Dictionary<K, V> dict(Tuple<? extends K, ? extends V>... ts); @SuppressWarnings("unchecked") static A[] toArray(Class<A> elemType, Collection<B> a); static double[] toDoubleArray(Collection<Double> as); @SafeVarargs static Iterator<A> iterator(final A... as); static Iterator<A> repeat(final X a, final int times); static Iterator<A> join(final Iterator<A> a, final Iterator<A> b); static Iterable<A> forc(final Iterator<A> as); static List<A> concat(M as);  }
@Test public void testFoldl() { List<Integer> ints = list(1, 2, 3, 4); assertTrue(10 == foldl(ints, 0, new Function2<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) { return a + b; } })); List<String> strings = list("vaughn", "bodé", "andré", "franquin"); assertTrue(23 == foldl(strings, 0, new Function2<Integer, String, Integer>() { @Override public Integer apply(Integer a, String s) { return a + s.length(); } })); assertTrue(5 == foldl(java.util.Collections.<Integer>emptyList(), 5, new Function2<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) { return a + b; } })); }