Hey guys - I���m wondering if someone might have a nice way of selecting the previous value in a list - but wrapping around to the last value if you are at the front.
Essentially I have an exercise with some values in a collection like:
list :=�� #($a $e $o $u).
And I have an index into the list, and want to loop around from index 1, back to 4 when I hit the beginning of the list.
While moving forwards is pretty easy with mod - e.g.
^list at: (index \\ list size + 1)
I���m struggling with the cleanest way to do this backwards - as the following is unreadable to me (assuming index = 1)
^list at: (index - 2 \\ list size + 1)
And then I tried (which isn't bad - but still not quite right).
^list before: (list at: index) ifAbsent: [ids last].
I���m sure there is a better way to do this - but it���s alluding me?
Tim