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

Dave Abrahams dabrahams at apple.com
Wed Dec 16 13:08:47 CST 2015


> On Dec 16, 2015, at 10:15 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
> On Wed, Dec 16, 2015 at 7:10 AM, Donnacha Oisín Kidney <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Now that I think about it, of course CollectionOfZeroOrOne would (or Optional) have a random access index. I’ll update the proposal to include that.
> 
> I really like the CollectionOfZeroOrOne solution. The semantics and types certainly make more sense. I’m not sure that it reduces the amount of code, though: the three extensions are still needed, plus an extra struct. (I suppose that’s not counting the extra version of LazyFilterCollection. Am I right in saying that that is intended to be added?)

I'm not sure I understand why we need another version of LazyFilterCollection.  Can you explain?

> Here’s what I have for the collection (I tried to mimic the standard library’s CollectionOfOne):
> 
> public struct CollectionOfZeroOrOne<Element> : CollectionType {
> 
> [...]
> }
> 
> Does that seem reasonable?
> 
> It looks reasonable, but I don't understand why adding CollectionOfZeroOrOne improves the API.  Dave?

It doesn't.  I think it improves code reuse, and gives people an adapter to use when they want to pass an Optional where a Collection or Sequence is required.

> 
> 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 <mailto:gribozavr at gmail.com>>*/

-Dave



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


More information about the swift-evolution mailing list