public static <A, B> Result<List<B>> traverse(List<A> list, Function<A, Result<B>> f) { return list.foldRight( Result.success(List.list()), x -> y -> Result.map2(f.apply(x), y, a -> b -> b.cons(a))); }
public static <A, B> B foldRight(List<A> list, B n, Function<A, Function<B, B>> f) { return list.foldRight(n, f); }