Skip to content

Instantly share code, notes, and snippets.

@sergio-castro
Created March 1, 2016 22:58
Show Gist options
  • Save sergio-castro/32ebe594dc14614d757e to your computer and use it in GitHub Desktop.
Save sergio-castro/32ebe594dc14614d757e to your computer and use it in GitHub Desktop.
//A collection of small Java 8 related utility methods, just for the fun of it.
public class Java8Tricks {
public static <T> Stream<T> stream(Iterator<? extends T> iterator) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false);
}
public static <A, B> Iterator<Entry<A, B>> zip(Iterator<? extends A> s1, Iterator<? extends B> s2) {
return Iterators.transform(s1, e1 -> immutableEntry(e1, s2.next()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment