[swift-evolution] [Pitch] Unify joined(separator:) and flatten()

Jacob Bandes-Storch jtbandes at gmail.com
Fri Jul 22 14:43:29 CDT 2016


On Fri, Jul 22, 2016 at 8:35 AM, Ben Rimmington <me at benrimmington.com>
wrote:

>
> > On 22 Jul 2016, at 02:46, Jacob Bandes-Storch wrote:
> >
> > In the swift-lang Slack channel, a few of us were discussing
> joined(separator:) and realized that flatten() does almost exactly the same
> thing.
> >
> > Is there interest in renaming flatten() to joined()?  Since joined takes
> a separator that's any Sequence, we can't have a default value for the
> separator parameter, but we can have a variant of joined() with no
> arguments.
>
> I'd like default separators for the joined() methods.
>
> <https://bugs.swift.org/browse/SR-1428>
>
> But renaming flatten() to joined() seems complicated.
>
> <
> https://github.com/apple/swift/blob/master/stdlib/public/core/Flatten.swift.gyb
> >
> <https://github.com/apple/swift/blob/master/stdlib/public/core/Join.swift>
>

What makes it seem complicated? At the very least, one could just rename
the flatten() function. There might also be an opportunity to combine the
two files and delete some code from stdlib.

>
> And what would happen to the flatMap() methods? Is flatten() a term of art?
>
> <
> https://github.com/apple/swift/blob/master/stdlib/public/core/FlatMap.swift
> >
>

I'd say flatMap is more a "term of art" than flatten. "flatten" just
describes literally what is being done. Frankly I'm surprised it was never
named flattened(). Anyway, flatMap should stay.


>
> -- Ben
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160722/15eb97e0/attachment.html>


More information about the swift-evolution mailing list