Skip to content

Instantly share code, notes, and snippets.

@greggirwin
Last active March 21, 2017 15:41
Show Gist options
  • Save greggirwin/f58f82eb2ef4e6d9b1c40d3f319b8d83 to your computer and use it in GitHub Desktop.
Save greggirwin/f58f82eb2ef4e6d9b1c40d3f319b8d83 to your computer and use it in GitHub Desktop.
Round-robin cycling through a series
Red []
cycler: context [
_data: none
_key: none
set-data: func [data [block!]][
_data: copy data
; Should we make sure the data conforms to our needs?
;if (last data) <> (first data) [
append/only _data first _data
;]
_key: last data
]
take: does [_key: select/only _data _key]
test: does [loop length? _data [probe take]]
]
cyc: make cycler []
cyc/set-data [0 1 2 3 4 5 6 7 8 9]
cyc/test
cyc: make cycler []
cyc/set-data [a #test 5x5 8 "key" %file 10%]
cyc/test
cyc: make cycler []
cyc/set-data [[a #test] [5x5 8] ["key" %file 10%]]
cyc/test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment