> Am 08.11.2017 um 21:25 schrieb John McCall <rjmcc...@apple.com>:
> 
>> My point is: The proposed filterMap isn’t a combination of map and filter at 
>> all — or can you build it just out of map & filter, like flatMap is 
>> constructed from map & flatten?
> 
> You can built it out of map and filter:
> 
>   func filterMap<T>(_ fn: (Element) -> U?) -> [U] {
>     return map(fn).filter { $0 != nil }.map { $0! }
>   }
True, but it’s not what I asked for — and it should rather be called 
„mapFilterMapForceUnwrap“, shouldn’t it? ;-)
The thing is that people who don’t fully understand flatMap (those that are the 
target group for the proposal) probably just use it because „it does a 
transformation and filters out nil (and nil is evil)“.
Renaming the function to filterMap hardens that misconception:
As you sample shows, filterMap is not like flatMap — the latter is honest 
(„flatten the result of map“) the other isn’t („filter the result of map“ only 
strips the nils, but doesn’t change the return type)

So I think it’s better to keep flatMap, or replace it with something that 
doesn’t pretend to be a plain filter.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to