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

Brent Royal-Gordon brent at architechies.com
Tue Jul 26 14:46:25 CDT 2016

> 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

More information about the swift-evolution mailing list