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

Kevin Ballard kevin at sb.org
Fri May 6 19:33:04 CDT 2016


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.

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

-Kevin


More information about the swift-evolution mailing list