scala-collection-contrib icon indicating copy to clipboard operation
scala-collection-contrib copied to clipboard

New circular Seq operations: rotateRight, rotateLeft, startAt

Open mcallisto opened this issue 3 years ago • 5 comments
trafficstars

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.

mcallisto avatar Jan 08 '22 17:01 mcallisto

Any positive or negative comment about this proposal?

mcallisto avatar Mar 07 '22 19:03 mcallisto

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.

som-snytt avatar May 25 '24 05:05 som-snytt

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.

mcallisto avatar May 25 '24 13:05 mcallisto

Why the applyO name? What does it mean?

OndrejSpanel avatar May 25 '24 14:05 OndrejSpanel

Why the applyO name? 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:

  • sliceO
  • indexOfSliceO
  • lastIndexOfSliceO
  • segmentLengthO
  • containsSliceO
  • slidingO

But if you think there is a better naming, I am happy to adopt it.

mcallisto avatar May 25 '24 14:05 mcallisto