[swift-evolution] [SHORT Review] SE-0132: Rationalizing Sequence end-operation names

Boris Wang kona.ming at gmail.com
Tue Jul 26 17:58:27 CDT 2016


the single word “first” only means one element,
but “prefix” can means multiple element.


Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org>于2016年7月27日
周三03:46写道:

> > On Jul 26, 2016, at 8:30 AM, Nevin Brackett-Rozinsky <
> nevin.brackettrozinsky at gmail.com> wrote:
> >
> > However, I believe that `first(n)` and `last(n)` read more clearly at
> the point of use than `prefix(n)` and `suffix(n)`.
>
> I've seen this a couple of times. It's something I bring up in "Other
> alternatives":
>
> > * We considered using `first` and `last` as the basis for both
> >   single-element and multiple-element operations (such that `prefix(3)`
> >   would become `first(3)`, etc.), but:
> >
> >   1. These seemed like distinct functionalities, particularly since
> >      their types are different.
> >
> >   2. We're not comfortable with heavily overloading a property with a
> >      bunch of methods, and didn't want to make `first` and `last` into
> >        methods.
> >
> >   3. Most APIs work fine, but `hasFirst(_:)` is atrocious, and we see
> >      no better alternative which includes the word `first`.
>
> To give you an idea of what I mean by #3:
>
>         if numbers.hasFirst([1, 2, 3, 4, 5]) && numbers.hasLast([5, 4, 3,
> 2, 1]) { … }
>
> Keeping those issues in mind, do you still prefer `first(n)` over
> `prefix(n)`?
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160726/faffe0de/attachment.html>


More information about the swift-evolution mailing list