Skip to content

Instantly share code, notes, and snippets.

@horus
Created December 1, 2014 07:52
Show Gist options
  • Select an option

  • Save horus/a4459733e53895b11b69 to your computer and use it in GitHub Desktop.

Select an option

Save horus/a4459733e53895b11b69 to your computer and use it in GitHub Desktop.
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