[swift-evolution] [Review] SE-0187: Introduce Sequence.filterMap(_:)

Vladimir.S svabox at gmail.com
Fri Nov 10 10:29:10 CST 2017


On 10.11.2017 18:37, BJ Homer via swift-evolution wrote:
> 
> 
>> On Nov 10, 2017, at 5:07 AM, Tino Heth <2th at gmx.de> wrote:
>>
>> A: Well, it does a mapping, and then applies a filter to get rid of nils,
> 
> I prefer to think of it this way: it does a mapping, and keeps the results where the closure did not return nil. In the example given earlier, the closure returned Optional<Int?>.some(nil), which is not “nil”.
> 

"So you can be sure that when you apply the filterMap method, the result doesn’t contain any nil values?"

Probably some code like this was shown then?:

let a : [[Int?]] = [[1,2,3,nil],[4,nil,5]]

print(a.flatMap{$0}) // [Optional(1), Optional(2), Optional(3), nil, Optional(4), nil, Optional(5)]

> -BJ
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
> 


More information about the swift-evolution mailing list