I have a Stream<A>
of n+1
elements and a functions B map(A a1,A a2)
which takes two elements of A
and returns one element of B
. Now I want to get a Stream<B>
of n
elements such that the i
-th element of the new stream is the result of map(a[i],a[i+1])
(here I used the square brackets of course informally). How would you do that?
Bonus: Is there even a more general solution which converts a Stream<A>
of n-m+1
elements using a function B map(A a1,A a2,...,A am)
to a Stream<B>
of n
elements?