Add Sequence.split(maxLength:)

You're right. What an irregular word.

But are filter, the drop family, dump, readLine, finalize not named for the verb action they take to produce the result?


“Split every 3” also works in the past tense IMHO, but I feel like this is going to be a distraction.

I’m leaning back towards maxLength: to reduce the amount of distraction, so we can focus on discussing the benefit to a Swift user, even though the bikeshedding will likely continue unabated.

Additional side thought: intoGroupsOf doesn’t clearly communicate the semantic that a group may be less than the given amount in a way that every: (forming a grammatical phrase) or maxLength: (not forming one) do.

I think I mentioned this earlier; but in case I haven't: in the Swift standard library, the terminology is usually "count" rather than "length." I'd be fine with something like split(maxCount:), although you do run into the ambiguity as to whether it's the maximum number of splits or the maximum number of elements per split. For full clarity, it'd probably have to be something like split(maxCountPerSplit:).

I disagree; it is well understood by anyone who has gone to elementary school that if you are asked to split into groups of three, sometimes there's a group of two. In fact I think that's the virtue of using a more colloquial expression such as that, because this implication is actually very strongly communicated.

filter is a term-of-art which pre-dates the naming guidelines and was grandfathered as a term-of-art exception.

drop* also pre-dates the naming guidelines; there was a proposal to rename these functions which could not be reviewed in the required timeframe, so we are stuck with them.

dump and readLine are free functions, which are not subject to the "ed/ing" rule because there is no self to mutate or not to mutate.

finalize is a consuming function; therefore, it adheres to the rule.

@xwu @zwaldowski I think both of these names work fine for me, but frankly I lean a little closer to split(every:) for ease of communication. IMO they're equally unambiguous and understandable.

But when I say it out loud, my tongue trips on split(intoGroupsOf:) a bit; it's a bit more cumbersome. Bear with me haha~

I realize it's a weird hangup, but as a programming instructor (and frequent participant in in-office debates :sweat_smile:) the ease of verbally communicating API is important to me. "This is a good opportunity to use split-every to solve this problem" rolls off my mind and mouth more easily than "This is a good opportunity to use split-into-groups-of to solve this problem". Just my 2¢.

1 Like
Terms of Service

Privacy Policy

Cookie Policy