[swift-evolution] [Review] Add a Lazy flatMap for Sequences of Optionals

Dave Abrahams dabrahams at apple.com
Tue Dec 15 20:29:26 CST 2015

First, I’d like to thank Oisin <https://github.com/oisdk> for his proposal.  It’s great to see people filling in gaps.

> 	* What is your evaluation of the proposal?

The basic idea is solid and obviously appropriate.  I have some quibbles with the proposed solution.

> 	* Is the problem being addressed significant enough to warrant a change to Swift?

Yes; it’s a non-uniformity, nonuniformities create complexity for users.

> 	* Does this proposal fit well with the feel and direction of Swift?


> 	* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

A quick reading, but I’m deeply familiar with the domain, having written the lazy facilities we have in the stdlib.

I don’t see why the proposal states, “Optional probably wouldn't have a BidirectionalIndexType“.  It seems to me that as a collection, an optional’s index should be random access, just like CollectionOfOne’s.

I’d like to suggest a different implementation approach that not only handles the bidirectional issue but also probably reduces the amount of code involved: create a generic CollectionOfZeroOrOne<T> that wraps a T?, and implement the x.flatmap(f) where f returns an optional as x.flatmap { CollectionOfZeroOrOne(f($0)) }

What do you think?


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

More information about the swift-evolution mailing list