[swift-evolution] [Review] SE-0172: One-sided Ranges

Haravikk swift-evolution at haravikk.me
Tue Apr 18 03:04:29 CDT 2017

> On 18 Apr 2017, at 05:40, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
> What is your evaluation of the proposal?
I like the principle of the proposal, but I have some concerns regarding the operators. In particular I don't like that it relies on prefix/postfix versions of the range operator, I'd prefer it to use the standard binary operator with Void as an argument like so:

func ... <T:Comparable>(lhs:T, rhs:Void) -> PartialRangeFrom<T> { … }
func ... <T:Comparable>(lhs:Void, rhs:T) -> PartialRangeTo<T> { … }

let rangeFrom = 5...()
let rangeTo = ()...5

With a view to having underscore in future as another alias for Void, so we can do the following:

let rangeFrom = 5..._
let rangeTo = _...5

Otherwise I like the basic idea (one-sided ranges) I just feel that the one-sidedness of the range operator should be explicit for safety, to avoid accidentally declaring a one-sided range somewhere that may accept one. This should also leave the ellipsis operators free for use in more specialised cases such as variadic tuples, tuple splatting etc.

> Is the problem being addressed significant enough to warrant a change to Swift?
It's relatively minor (there are workarounds), but I'd say so.

> Does this proposal fit well with the feel and direction of Swift?
Yes, aside from the accident safety mentioned above.

> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Read during discussion and re-read now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170418/3e34abdf/attachment.html>

More information about the swift-evolution mailing list