[swift-evolution] [Draft] Rationalizing Sequence end-operation names

Brent Royal-Gordon brent at architechies.com
Tue Jun 28 17:40:24 CDT 2016

> I was in the midst of writing a reply along the same lines, so I figured I'd add to David's reply here. There are two characteristics I would expect from a method named "prefix" or "suffix".
> First, it should return a subsequence containing zero to count elements. (By contrast, something named "first" should return nil or one element, but certainly no more.)
> Second, in the case of "prefix", the first element of the subsequence (if any) should be the first element of the sequence; in the case of "suffix", the last element of the subsequence (if any) should be the last element of the sequence.

I would phrase these things slightly differently. In my thinking, a method with `prefix` or `suffix` in its name:

	1. Operates on a subsequence at the beginning/end of the sequence,

	2. Measured *relative* to the beginning/end.

An index-based operation doesn't fit this definition because an index is not *relative* to anything—it's an *absolute* position within the sequence.

Put another way, in my view, "prefix" and "suffix" don't merely mean "anchored at the beginning/end". A prefix or suffix is attached to a "middle". There is no middle in the index-based operations.

It is, of course, very possible to use methods to express what the index-based operations do:


But at this point, we've basically arrived at `friends[to: i]` etc.

Brent Royal-Gordon

More information about the swift-evolution mailing list