scala-collection-contrib
scala-collection-contrib copied to clipboard
New circular Seq operations: rotateRight, rotateLeft, startAt
I would like to add to Seq several operations, all related to considering a Seq (or a subtype) a circular sequence.
If you take a look at my library repo at https://github.com/scala-tessella/ring-seq, these are all the methods that I have in mind.
But I started here adding just three, since I need to get used to the intricacies of the Scala collections.
If this is of interest, I will have many more questions on how to correctly add other methods.
Any positive or negative comment about this proposal?
rotate seems pretty natural. (Also << and >>, see BitSetDecorators.)
I'm not sure if it's more natural as a view, like slices, an operation on indexes.
The decisions to be taken are what to ingest here and in what form, and also whether it works better as a library.
I would agree with the previous review that startAt is too much, but rotateLeft and rotateRight, as a simple alias to swap slices and build a result, are handy.
I see that this repo has a lower barrier to entry.
Thank you @som-snytt for coming back to this issue. I deleted startAt and added applyO which I feel is another needed building block when handling circular sequences.
Why the applyO name? What does it mean?
Why the
applyOname? What does it mean?
It stands for applyCircular or applyRing, where the O suffix is a circle or a ring.
In fact it behaves like apply, but accepts a circular index rather than a standard one.
When looking at the issue, consider that, in perspective, these other methods could have a circular alternative:
sliceOindexOfSliceOlastIndexOfSliceOsegmentLengthOcontainsSliceOslidingO
But if you think there is a better naming, I am happy to adopt it.