Skip to content

Instantly share code, notes, and snippets.

@kdabir
Created October 13, 2016 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdabir/aedff5fde47a209197302de09c1a2e2b to your computer and use it in GitHub Desktop.
Save kdabir/aedff5fde47a209197302de09c1a2e2b to your computer and use it in GitHub Desktop.
Boilerplate function for mapping a list to another using stream API internally. Note that this defeats the purpose of streams, which are lazy and combine operations together. Use it only for one level of mapping where logic is not piped and results need to be immediately realized.
static <T, R> List<R> map(List<T> list, Function<? super T, ? extends R> mapper) {
return list.stream().map(mapper).collect(Collectors.toList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment