I'm trying to implement a Map function which takes two java.util.stream.Stream inputs, applies an operation to correspondingly-indexed items, and returns a Stream of the outputs. Here is what I want my method signature to look like:
public static <T, U, R> Stream<R> map(Stream<T> stream1, Stream<U> stream2, BiFunction<T, U, R> mapper)
Basically something analogous to the following Lisp (specifically Clojure):
> (map * '(2 3 4) '(8 4 3))
(16 12 12)
I'm pretty sure there is no built-in or standard way to do this, and my best bet is to turn both input streams into spliterators (or iterators if you want to be lame about it), consume values as the streams produce them, and apply the operator to them to produce the output stream.
In other words, while if I do this right I will end up with something which functional-ish when used externally, the internal implementation will be rather messy and imperative looking. Is there an alternative approach I ought to be considering?