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

Dmitri Gribenko gribozavr at gmail.com
Tue Dec 15 20:37:11 CST 2015


On Tue, Dec 15, 2015 at 6:29 PM, Dave Abrahams via swift-evolution <
swift-evolution at swift.org> wrote:

> 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's the advantage?  Why would we want to have a type that is isomorphic
to Optional, except that conforms to CollectionType?

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151215/810b71a4/attachment.html>


More information about the swift-evolution mailing list