<div dir="ltr"><div>I'll argue in favor of names which include the term "some".</div><div><br></div><div>"The Optional type is an enumeration with two cases. Optional.none is equivalent to the nil literal. Optional.some(Wrapped) stores a wrapped value." (<a href="https://developer.apple.com/documentation/swift/optional">https://developer.apple.com/documentation/swift/optional</a>)</div><div><br></div><div><div><font face="monospace, monospace">let things = ["apple", nil, "cat", "dog"]</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">print( things )</font></div><div><font face="monospace, monospace">print( things.flatMap {$0} )</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">// Equivalently: apply map, filter for non-nil, and apply force unwrap.</font></div><div><font face="monospace, monospace">func transform(x: Any?) -> Any? {return x}</font></div><div><font face="monospace, monospace">print( things.map(transform).filter { $0 != nil }.map { $0! } )</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">for x in things {</font></div><div><font face="monospace, monospace"> switch x {</font></div><div><font face="monospace, monospace"> case .some:</font></div><div><font face="monospace, monospace"> print(x!)</font></div><div><font face="monospace, monospace"> case .none:</font></div><div><font face="monospace, monospace"> break</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">[Optional("apple"), nil, Optional("cat"), Optional("dog")]<br></font><font face="monospace, monospace">["apple", "cat", "dog"]<br></font><font face="monospace, monospace">["apple", "cat", "dog"]<br></font><font face="monospace, monospace">apple<br></font><font face="monospace, monospace">cat<br></font><font face="monospace, monospace">dog</font></blockquote></div><div><br></div><div>Here's a variety of possible new names, in descending order of personal preference:</div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">mapUnwrappingSome</font></div><div><span style="font-family:monospace,monospace">mapAndUnwrap // Thanks Nevin, this is surprisingly clear.</span><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">mapUnwrapSome</font></div><div><font face="monospace, monospace">mapUnwrapIfSome</font></div><div><font face="monospace, monospace">mapSome // For these last three, it's unclear when nil elements are dropped. Before or after the map?</font></div><div><font face="monospace, monospace">mapNonNil</font></div><div><font face="monospace, monospace">mapStrippingNil</font></div><div><br></div><div>I'm opposed to <font face="monospace, monospace">filterMap</font>. Combining the names of two commonly used methods for this less frequent operation seems likely to cause as much confusion as flatMap.</div><div>I'm opposed to <font face="monospace, monospace">compactMap</font>. There are two English meanings of "compact", and my initial thought was about enforcement of some kind of contract.</div><div>I think <font face="monospace, monospace">mapUnwrappingSome</font> is explicit, puts clarity > brevity, and maintains naming consistency within Swift. If the enumeration cases .some and .none are taught along with Optionals, then this name is clear.</div><div><br></div><div>That's my 2-cents as a relatively inexperienced user.</div><div>-Dylan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 15, 2017 at 6:48 PM, Nevin Brackett-Rozinsky via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Wed, Nov 15, 2017 at 8:05 PM, Wallacy via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="auto">“unwrappingMap”(or some variations using unwrap).</div></div></div></blockquote><div><br></div></span><div> I’d like to propose “mapAndUnwrap”.</div><div><br></div><div>It does what it says on the tin: map a sequence (into an optional type), then unwrap the values which exist.</div><div><br></div><div>Nevin</div></div></div></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>