Skip to content

Instantly share code, notes, and snippets.

@mdread
Created May 3, 2013 12:52
Show Gist options
  • Save mdread/5508938 to your computer and use it in GitHub Desktop.
Save mdread/5508938 to your computer and use it in GitHub Desktop.
functional "map" for java
public static <R extends Iterable<K>, K, V> R map(Iterable<V> iter, Function<V, K> func){
List<K> result = new LinkedList<K>();
for (V sourceValue : iter) {
result.add(func.apply(sourceValue));
}
return (R)result;
}
public static interface Function<S, R> {
R apply(S value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment