arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
707 stars 32 forks source link

[Iterators] add `.rolling` option #1030

Open github-actions[bot] opened 1 year ago

github-actions[bot] commented 1 year ago

[Iterators] add .rolling option

this would allow us to have a rolling window of values

for example, if we have a list of 10 values, and we want to

iterate over it with a window of 3 values, we would get:

[1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9,10]

https://github.com/arturo-lang/arturo/blob/ed0410b81b479dcf090b239e2193a45ecf65cd5d/src/library/Iterators.nim#L12

## (part of the standard library)

# TODO(Iterators) add `.rolling` option
#  this would allow us to have a rolling window of values
#  for example, if we have a list of 10 values, and we want to
#  iterate over it with a window of 3 values, we would get:
#  `[1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9,10]`
#  labels: library, enhancement

#=======================================
# Pragmas
#=======================================
ndex 403bef8a72..a0aa11d4c2 100644
++ b/src/library/Numbers.nim

ee6fca73fa4f70e752f77f0c2e09c36f7ee6e9ec

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 7 months ago

Closing issue as stale.

Eloitor commented 1 month ago

I propose .offset: instead. By default .offset: is the same as the size of the window. Setting .offset: to 1 we would get the behavior of the .rolling option defined here.

.offset: is more flexible.