[swift-evolution] rename dropFirst() and dropLast()

Daniel Duan daniel at duan.org
Tue Dec 29 13:55:43 CST 2015

Hi Kevin,

“take" and “skip” are fine as free function names. As method names, they are a step back from following the API Guidelines (“non-mutating methods should read as noun phrases”).

- Daniel

> On Dec 29, 2015, at 11:40 AM, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
> On Mon, Dec 28, 2015, at 04:23 PM, Kevin Ballard wrote:
>> That said, `droppingFirst` sounds pretty weird to me. "drop" (and the related verb "take" that we're not using) has precedent in multiple languages (Rust and Haskell come to mind) to mean "return a new sequence that skips the first N elements". And I'm not aware of any language that sets precedent for the verb "drop" to mean "mutate the receiver".
> Hmm, I just took a look, and while Rust does use "take", it actually doesn't use "drop" (but Haskell does). Instead it uses "skip", which seems like a good candidate if we're going to rename this. I'm tempted to say we should use "take" instead of "prefix" as well, because `seq.prefix(3)` isn't actually immediately obvious what it does (as the verb "prefix" usually means to add onto the front, not to take the front). And we can use "takeLast" for "suffix" (neither Rust nor Haskell appears to have an equivalent of takeLast; I believe Rust doesn't because none of its iterator adaptors use dynamically-allocated memory, and I think Haskell expects you to just do `reverse . take n . reverse`). Although I do notice Haskell has a function dropWhileEnd that drops the suffix, which suggests "takeEnd" and "dropEnd" here.
> Which is to say, if we're going to rename these methods, my vote is:
> prefix -> take
> suffix -> takeEnd or takeLast
> dropFirst -> skip
> dropLast -> skipEnd or skipLast
> -Kevin Ballard
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list