Created
December 11, 2015 10:47
-
-
Save amaembo/337ad5f3ccd09dc71a30 to your computer and use it in GitHub Desktop.
Lukas Eder Readability samples using StreamEx
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.Arrays; | |
import java.util.List; | |
import one.util.streamex.IntStreamEx; | |
import one.util.streamex.StreamEx; | |
public class Readability { | |
public static void main(String args[]) { | |
// Sample 1 | |
List<Integer> list = Arrays.asList(1, 2, 3); | |
StreamEx.of(list).cross(i -> IntStreamEx.range(i).boxed()) | |
.forKeyValue((i, j) -> System.out.println(i * j)); | |
// Sample 2 | |
List<Character> alphabet = IntStreamEx.rangeClosed('A', 'Z') | |
.mapToObj(ch -> (char) ch).toList(); | |
int max = 3; | |
IntStreamEx.rangeClosed(1, max) | |
.flatMapToObj(len -> StreamEx.cartesianPower(len, alphabet, "", (a,b) -> a+b)) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment