Skip to content

Instantly share code, notes, and snippets.

@dlinsin
Created November 5, 2009 15:57
Show Gist options
  • Save dlinsin/227157 to your computer and use it in GitHub Desktop.
Save dlinsin/227157 to your computer and use it in GitHub Desktop.
static <T,U> List<U> map(List<T> list,{T=>U} transform) {
List<U> result = new ArrayList<U>(list.size());
for (T t : list) { result.add(transform.invoke(t)); }
return result;
}
public static void main(String[] args) {
List<Color> colors = map(Arrays.asList(Flavor.values()), { Flavor f => f.color });
System.out.println(colors.equals(Arrays.asList(Color.values())));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment