[swift-evolution] [Accepted with modifications] SE-0045: Add scan, prefix(while:), drop(while:), and unfold to the stdlib

Dave Abrahams dabrahams at apple.com
Fri May 6 20:05:14 CDT 2016


on Fri May 06 2016, Kevin Ballard <swift-evolution at swift.org> wrote:

> On Fri, May 6, 2016, at 05:31 PM, Kevin Ballard wrote:
>> On Fri, May 6, 2016, at 05:19 PM, Dave Abrahams via swift-evolution wrote:
>> > 
>> > on Wed May 04 2016, Chris Lattner <swift-evolution at swift.org> wrote:
>> > 
>> > > Proposal link: https://github.com/apple/swift-evolution/blob/master/proposals/0045-scan-takewhile-dropwhile.md
>
>> > >
>> > > Hello Swift Community,
>> > >
>> > > The review of SE-0045: "Add scan, prefix(while:), drop(while:), and
>> > > unfold to the stdlib" ran from April 28...May 3, 2016. A subset of the
>> > > proposal is *accepted, with modifications* for Swift 3.  This proposal
>> > > included four new additions to the standard library:
>> > >
>> > > Sequence.prefix(while:) & Sequence.drop(while:) - These are *accepted* as specified in revision 3 of the proposal.
>> > 
>> > I know the review is over and all, but…
>> > 
>> > Chris brought to my attention an idea that I liked, and asked me to post
>> > here about it.  Specifically, the argument label “where:” would probably
>> > be better than “while:”.  “While” makes it sound to me like it's going
>> > to take a nullary predicate and be much more active.  But it's hard to
>> > love
>> > 
>> >      s.drop(where: { $0 > 1 })
>> >      s.drop { $0 > 1 }
>> > 
>> > because it makes it sound like a general filtering operation.
>> > 
>> > Therefore, I'd much rather see
>> > 
>> >        s.droppingPrefix(where: {$0 > 1})
>> 
>> Using "where:" has a very high potential for confusion, because
>> "where" makes it sound like it runs the predicate against every
>> single element, whereas "while" makes it clear that it stops
>> evaluating elements once the predicate returns false. Or in other
>> words, `drop(where: predicate)` looks like it should be equivalent
>> to `filter({ !predicate($0) })`.
>
> Oops, I read your message too fast and missed the fact that you
> changed the function name too in the very last line.

And made the exact point that you made :-)

> If we switched to `droppingPrefix(where:)` then we'd need to change `dropFirst(_:)` as well.

Yes, as I noted in my response to Erica, I would like to see some more design
coherence in this whole area.  I think

          xs.dropFirst()  =>  xs.droppingFirst()
          xs.dropFirst(3) => xs.droppingPrefix(ofMaxLength: 3)

I'm not wedded to “dropping,” especially because it has other
connotations.  Dmitri, Max, and I kicked around a bunch of other
possibilities, e.g.

          sansPrefix
          withoutPrefix

Anyway, we can't do all of that by the seat of our pants.  I personally
wouldn't want to go any further than s.dropPrefix(where: ...)  without a
new proposal/review.

-- 
Dave



More information about the swift-evolution mailing list