[swift-evolution] [Review] SE-0078: Implement a rotate algorithm, equivalent to std::rotate() in C++
Xiaodi Wu
xiaodi.wu at gmail.com
Tue May 3 23:51:39 CDT 2016
> * What is your evaluation of the proposal?
>
+1. A very useful function to have on collections.
In FORTRAN and in languages that take inspiration from it, the same
function is called a "circular shift"--IMO, it's a clearer name both by its
associations with other uses of the term "shifting" and because googling
the term will give much more useful results.
IMO, the parameter label could also use some bikeshedding. One reason is
that, with an `Array<Int>` (as illustrated in the examples given), the
argument in `array.rotate(firstFrom: 5)` does not obviously refer to an
index. Superficially, this could mean first from the first element equal to
5.
One suggestion I would put forward is: `circularShift(leftBy:
IndexDistance)`. For bidirectional and random access collections, this
function could possibly be complemented by `circularShift(rightBy:
IndexDistance)`.
Finally, I wonder whether the C++11-like behavior of returning the new
index of the former first item is a very Swifty behavior. I could be
persuaded if the return value is demonstrably something that is not always
trivial to compute.
* Is the problem being addressed significant enough to warrant a
> change to Swift?
>
It's an additive feature, and it's hard to see any drawbacks.
> * Does this proposal fit well with the feel and direction of Swift?
>
Yes, it's an algorithm of appropriate complexity and general utility to be
added to the stdlib.
> * If you have used other languages or libraries with a similar
> feature, how do you feel that this proposal compares to those?
>
This proposal presents the same algorithm as found in other languages but
borrows the name from C++. Other names may be more self-documenting (see
above).
> * How much effort did you put into your review? A glance, a quick
> reading, or an in-depth study?
>
I have read the proposal to a medium depth.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160503/2db76f05/attachment.html>
More information about the swift-evolution
mailing list