Created
October 13, 2016 12:28
-
-
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.
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
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