Interacting with current and next iterator

Say a is an iterator (not a vector or anything that can be indexed). I have function f(x,y) = x+y, and I want to have the function act on successive values of a.

Say for our example a is an iterator for all odd numbers starting from 1. The expected behavior is for f to return f(3,1)=4, then f(5,3)=8, etc. Thus far I could not find a way to preserve state through iterations like this without using a global variable then storing the value of the iterator there.

Is there a way to do what I’m looking for?

IterTools.partition(a,2,1)?

Does partition(iterator_of_odds, 2, 1) from IterTools.jl do what you need?

https://juliacollections.github.io/IterTools.jl/stable/#partition(xs,-n,-[step])

In [3]: using IterTools

In [4]: v = 1:2:21
Out[4]: 1:2:21

In [5]: collect(partition(v, 2, 1))
Out[5]: 10-element Vector{Tuple{Int64, Int64}}:
 (1, 3)
 (3, 5)
 (5, 7)
 (7, 9)
 (9, 11)
 (11, 13)
 (13, 15)
 (15, 17)
 (17, 19)
 (19, 21)