Created
May 6, 2013 11:47
-
-
Save lichenbo/5524685 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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