Hi,
I think there should be a 'reverse' macro for reversed traversal of iterators which doesn't change the original content nor creates a duplicate (or something similar) - I tried to search for something like this but I did find only procs algorithm.reverse(), algorithm.reversed() which reverse the seq itself. Sorry if a such thing exists...
Example:
let arr = @[1,2,3,4]
for item in arr.reversedTraversal(): # No copy created
echo item
# 4
# 3
# 2
# 1
# Maybe even this?
echo arr.reversedTraversal() # @[4,3,2,1]
# Original not changed
echo arr # @[1,2,3,4]
I agree that it should be in the stdlib, but it's fairly easy to implement
iterator reversed*[T](arr: openArray[T]): T =
for it in countdown(arr.high, arr.low):
yield arr[it]