[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:17:40 CDT 2016


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

> On May 6, 2016, at 6:27 PM, Dave Abrahams via swift-evolution
> <swift-evolution at swift.org> wrote:
>
>     on Thu May 05 2016, Erica Sadun
>     <swift-evolution at swift.org> wrote:
>
>         On May 4, 2016, at 5:50 PM, Chris Lattner via swift-evolution
>         <swift-evolution at swift.org> wrote:
>
>         Proposal link:
>         https://github.com/apple/swift-evolution/blob/master/proposals/0045-scan-takewhile-dropwhile.md
>
>         Sequence.prefix(while:) & Sequence.drop(while:) - These are *accepted*
>         as
>         specified in revision 3 of the proposal.
>
>         I'm still a little sad we didn't go for `prefix`/`suffix` or `take`/
>         `drop` pairs
>         that linguistically matched.
>
>     I think building an API family around “prefix” and “suffix” that covers
>     this and other functionality is a great idea, and would make a great
>     proposal**
>
>     This whole area needs some design love. Among other things,
>
>     s.prefix(4)
>
>     should be
>
>     s.prefix(ofMaxLength: 4)
>
>     ** though we haven't been able to completely eliminate the moral
>     equivalent of “drop” from the “dropWhile” function, whatever it's
>     eventually called, in any of our experiments
>
> I'm sure that Kevin or I or some other proposalista could put together a quick
> fast-track rename request for
>
> * suffix(n) -> Self.SubSequence // requires `n >= 0`, `n <= count`
> * suffix(maxLength: n) -> Self.SubSequence // requires `n >= 0`
> * suffix(while: predicate) -> Self.SubSequence
> * prefix(n) -> Self.SubSequence
> * prefix(maxLength: n) -> Self.SubSequence
> * prefix(while: predicate) -> Self.SubSequence

Not *too* quick, please.  This area needs some thought and attention. :-)

>
>
>     Nonetheless I'm gratified these are hopping into the language. That
>
>     said, I'm going to put on my painters cap to consider selecting some
>         exterior latex for the feature I was most looking forward to in this
>         proposal:
>
>         Core team writes:
>
>         unfold(_:applying:) - This addition is *rejected* by the core team as
>         written, but deserves more discussion in the community, and potentially
>         could be the subject of a future proposal. The core team felt that the
>         utility of this operation is high enough to be worth including in the
>         standard library, but could not find an acceptable name for it. “unfold”
>         is
>         problematic, despite its precedence in other language, because Swift
>         calls
>         the corresponding operation “reduce” and not “fold”. No one could get
>         excited about “unreduce”. “iterate” was also considered, but a noun is
>         more
>         appropriate than an verb in this case. Given the lack of a good name,
>         the
>         core team preferred to reject to let the community discuss it more.
>
>         A few thoughts:
>
>         * I'm not sure why a noun is more appropriate than a verb. Reduce isn't
>         a noun,
>         prefix isn't a noun, drop isn't a noun. 
>
>     Can't let that one go by; prefix is definitely a noun :-)
>
> I knew you'd point that out. It's not a noun when it's wearing its "I AM
> VERBING" t-shirt.

It only ever wears http://www.memidex.com/shirtfront+insert

> That aside, the prevailing sentiment is to rename reduce to `fold` and partner
> it with `unfold`.
> (I personally prefer Chris's `sequence` because I think it better reflects how
> more Swift users will
> use it (never for;;get; never sur;;render). 

That's not “unfold,” FWIW.

> But I recognize that terms of art have a strength of momentum and
> familiarity.)
>
> -- E
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
Dave



More information about the swift-evolution mailing list