Created
August 29, 2020 12:48
-
-
Save lcs-felix/03f67ec0a5d0644717aa46b3e0c08a4e to your computer and use it in GitHub Desktop.
This file contains 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
public class Main { | |
public static void main(String[] args) { | |
List<Integer> result = mymap(asList(1, 2, 3, 4, 5), | |
n -> n * n); | |
System.out.println(result); | |
} | |
static <T> List<T> mymap(List<T> list, Function<T, T> func) { | |
return list.stream() | |
.reduce(new ArrayList<T>(), | |
(a, b) -> {a.add(func.apply(b)); return a;}, | |
(a, b) -> {a.addAll(b); return a;}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment