Last active
March 14, 2017 17:24
-
-
Save animatedlew/c71cfc259662818cb8cb0c0eea7a478e 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
package com.company; | |
import java.util.Arrays; | |
import java.util.Iterator; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; | |
public class Main { | |
private static int consume(int a, int b) { | |
return a + b; | |
} | |
public static void main(String[] args) { | |
Stream<Integer> xs = Arrays.stream(new Integer[] {1, 2, 3, 4, 5}); | |
Stream<Integer> ys = Arrays.stream(new Integer[] {9, 8, 7, 6, 5}); | |
Iterator<Integer> xi = xs.iterator(); | |
Iterator<Integer> yi = ys.iterator(); | |
IntStream | |
.iterate(0, n -> n + 1) | |
.filter(i -> xi.hasNext() && yi.hasNext()) | |
.map(n -> consume(xi.next(), yi.next())) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment