[swift-evolution] [Review] SE-0187: Introduce Sequence.filterMap(_:)
Michel Fortin
michel.fortin at michelf.ca
Sat Nov 11 16:08:52 CST 2017
Oh right. I guess that makes most of my review beside the point then. Sorry.
> Le 11 nov. 2017 à 14:46, BJ Homer <bjhomer at gmail.com <mailto:bjhomer at gmail.com>> a écrit :
>
>
>
>> On Nov 11, 2017, at 9:49 AM, Michel Fortin via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> I think it fits well for arrays. Not sure about optionals.
>
> This proposal only suggests changing the one on sequences, and even then, not all of them. Currently, the following exist:
>
> // Reminder: Int("someString") returns 'Int?' in the following examples
>
> // (1) Sequence.flatMap() with a closure returning an optional, dropping anything that maps to nil
> ["1", "mountain", "2"].flatMap({ Int($0) }) // [1, 2]
>
> // (2) Sequence.flatMap() with a closure returning a sequence, then joining (“flattening”) them into one array
> [1, 2, 3].flatMap({ Array(1...$0) }) // [1, 1, 2, 1, 2, 3]
>
> // (3) Optional.flatMap() with a closure returning an optional, flattening a nested optional.
> ("3" as String?).flatMap({ Int($0) }) // Optional(3)
>
>
> The 2nd and 3rd variants are both about flattening nested structures, and would not change under this proposal. We would keep calling them “flatMap()”. There is no a proposal to add Optional.filterMap, nor to change the Sequence.flatMap variant that flattens nested sequences. The only change proposed it is to rename the first one.
>
> -BJ
--
Michel Fortin
https://michelf.ca <https://michelf.ca/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171111/8f63fde6/attachment.html>
More information about the swift-evolution
mailing list