Skip to content

Instantly share code, notes, and snippets.

@lichenbo
Created May 6, 2013 11:47
Show Gist options
  • Save lichenbo/5524685 to your computer and use it in GitHub Desktop.
Save lichenbo/5524685 to your computer and use it in GitHub Desktop.
interface Func<B,A> {
B m(A x);
}
static <A,B> List<B> map(Func<B,A> f, List<A> xs) {
if (xs == null) return null;
return new List<B>(f.m(xs.head),map(f,xs.tail));
}
static List<Integer> doubleAll (List<Integer> xs) {
return List.map((new Func<Integer,Integer>(){
public Integer m(Integer x) {
return x*2;
}
}),xs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment