Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active March 14, 2017 17:24
Show Gist options
  • Save animatedlew/c71cfc259662818cb8cb0c0eea7a478e to your computer and use it in GitHub Desktop.
Save animatedlew/c71cfc259662818cb8cb0c0eea7a478e to your computer and use it in GitHub Desktop.
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