[swift-evolution] [SR-933] Rename flatten to flattened

Pyry Jahkola pyry.jahkola at iki.fi
Fri Apr 8 06:00:45 CDT 2016


> On 08 Apr 2016, at 13:19, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I think it makes sense to just rename them; it’s not as though flattened or mapped is somehow far removed from the original meaning as the actual action is the same, it’s just changing tense.

-1, and not only for the reasons we neither call trigonometric functions `sine`, `cosine`, and `tangent`. The existing names are widely known, commonly taught in modern introductory programming courses, to the point, and googleable.

In addition:

> If we want mutating forms of this methods then I much prefer .map() and .mapped() to .map() and .mapInPlace() or whatever, as the latter contradicts the naming convention used everywhere else which only adds confusion.

This idea of in-place versions is innocuous but absurd. In general, there's no way mapping `T -> U` over a `[T]` could possibly accommodate the result in the argument of type `[T]`:

    var xs: [Int] = ...
    xs.mapInPlace {String($0)} // ???

And the same goes for `flatMap`, and `Optional` and others. Likewise, `flatten()` couldn't possibly happen in place because the result type has one level of nesting less than the argument.

— Pyry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160408/cbf6f8df/attachment.html>


More information about the swift-evolution mailing list