[swift-evolution] [Pitch] Rename flatten() to joined() and give joined() for string sequences the empty string as the default parameter

Tim Vermeulen tvermeulen at me.com
Fri Jul 22 13:34:22 CDT 2016


someSequence.joined(separator: [])

(where someSequence is a sequence of sequences) results in two equal sequences (apart from their exact types). I would like to have flatten() renamed to joined(), resulting in joined(_:) seemingly having an empty array as the default parameter.

Similarly, I propose to give joined(_:) for a sequence of strings the empty string as the default parameter, allowing us to replace something like

["Hello, ", "world!"].joined(separator: "") // "Hello, world!"


["Hello, ", "world!"].joined() // "Hello, world!”

In other words, I think joined(_:) should have a default parameter of either `[]` or `””` and flatten() could then be removed as it would act the exact same way as joined().
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160722/78cc663d/attachment.html>

More information about the swift-evolution mailing list