<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 13 nov. 2017 à 04:35, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 8, 2017, at 9:29 PM, Paul Cantrell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">The problem in the Doodads example is that<span class="Apple-converted-space">&nbsp;</span><b class="">the name&nbsp;<span class="" style="color: rgb(88, 126, 168); font-family: Menlo; font-size: 11px;">flatMap</span>&nbsp;is used to identify two distinct intents</b>: concatenating arrays and filtering nils. One can argue that those two operations are, in some lofty abstract sense, if you squint, two instances of some more general pattern — but I don’t think it’s fair to say that they represent the same<span class="Apple-converted-space">&nbsp;</span><i class="">intent</i>. These separate intents deserve separate names.</div></div></blockquote><br class=""></div><div class="">I think that's the crux of it.</div><div class=""><br class=""></div><div class="">I think we might be better off renaming the maps on `Optional` and then naming the `Sequence` operation analogously. For instance:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Optional.map(transform) =&gt; Optional.pass(to: transform)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Optional.flatMap(transform) =&gt; Optional.chain(to: transform)</div><div class=""><br class=""></div><div class="">Then this would be a natural choice:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Sequence.flatMap(transform) =&gt; Sequence.chainMap(transform)</div><div class=""><br class=""></div><div class="">Alternatively, we could think of a name for "removing optionality from a sequence" and then use that name. For example, borrowing a name from Ruby:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(Sequence where Element == T?).compact()</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Sequence.compactMap(transform)</div><div class=""><br class=""></div><div class="">Actually, "unwrapped" might be a better name than "compact", since we use that term.</div></div></div></blockquote><div><br class=""></div>`unwrap` is in the air, I agree. Before I suggested compactMap as well, above, I had a look at the RxSwift method name for filtering out nils from observable sequences. It is defined in RxSwiftExt, and named `unwrap`:&nbsp;<a href="https://github.com/RxSwiftCommunity/RxSwiftExt#unwrap" class="">https://github.com/RxSwiftCommunity/RxSwiftExt#unwrap</a></div><div><br class=""></div><div>Yet I wouldn't follow that precedent. As Erica Sadun has told us, there is something interesting in "unwappable" types. It's a clear concept. Yet it applies to *values*, not *collections*: Optional.unwrapped, Result.unwrapped, but not Array.unwrapped. Optional&lt;Array&lt;Result&gt;&gt;.unwrapped().unwrapped() is a conceptual mess.</div><div><br class=""></div><div>The functional vocabulary does not help us much, here. What about calling a spade a spade? "Filtering out nils" is not general enough to fit in the functional landscape, but it happens to be a concept that has is clear, useful, and stand-alone. "Compact" fits this precise niche very well.</div><div><br class=""></div><div>Gwendal Roué</div><div><br class=""></div></body></html>