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

Kevin Ballard kevin at sb.org
Wed Nov 8 16:47:56 CST 2017


On Wed, Nov 8, 2017, at 02:29 PM, Max Moiseev via swift-evolution wrote:> 
> 
>> On Nov 8, 2017, at 12:20 PM, Tino Heth <2th at gmx.de> wrote:
>> 
>> 
>>> This is a wonderful example! But it’s an argument for a different
>>> discussion (of general usefulness of implicit optional promotion).
>>> Thanks to the optional promotion, what the closure returns is not
>>> nil, but instead is .some(nil), and that is not filtered out.>> 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?> https://github.com/apple/swift/blob/master/stdlib/public/core/FlatMap.swift#L49> 
> It *is* a combination of map and filter. It is purely for performance
> we don’t do the same thing on any Sequence, because that will allocate
> a temporary array or two.
Well, that certainly explains the nasty return type. I rather wish we
had a LazyFlatMapSequence type rather than using map(…).filter(…).map(…)
if for no other reason than it would produce a return type that's easier
to work with.
-Kevin Ballard

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171108/b360b78e/attachment.html>


More information about the swift-evolution mailing list