Indexing
applyO
The circular equivalent of apply
.
Note
Given the definition of circular sequence, it returns an element for any possible integer.
Example
Seq(0, 1, 2).applyO(3) // 0
Compared to standard
In the same example the standard version behaves differently, does not return an element, it throws.
Seq(0, 1, 2).apply(3) // IndexOutOfBoundsException
Not a total function
It does not return a value for an empty sequence.
Seq.empty.applyO(0) // ArithmeticException
indexFrom
Converts a circular index into a standard index.
Example
Seq(0, 1, 2).indexFrom(30001) // 1
The source code for this page can be found here.