Skip to content

Instantly share code, notes, and snippets.

@amaembo
Created December 11, 2015 10:47
Show Gist options
  • Save amaembo/337ad5f3ccd09dc71a30 to your computer and use it in GitHub Desktop.
Save amaembo/337ad5f3ccd09dc71a30 to your computer and use it in GitHub Desktop.
Lukas Eder Readability samples using StreamEx
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