Created
December 1, 2014 07:52
-
-
Save horus/a4459733e53895b11b69 to your computer and use it in GitHub Desktop.
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
| import java.util.function.*; | |
| import java.util.stream.*; | |
| public class Test { | |
| public static void main(String[] args) { | |
| Supplier<Integer> times = () -> 3; | |
| Function<Integer, String> dotimes = x -> { | |
| String val; | |
| switch(x) { | |
| case 1: val = "once"; | |
| break; | |
| case 2: val = "twice"; | |
| break; | |
| default: val = x + " times"; | |
| break; | |
| } | |
| return val + "!"; | |
| }; | |
| Consumer<String> cs = x -> System.out.println(x); | |
| IntStream.range(0, times.get()) | |
| .map(t -> t+1) | |
| .forEach(n -> {cs.accept(dotimes.apply(n));}); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment