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?