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

Dmitri Gribenko gribozavr at gmail.com
Wed Dec 16 12:15:08 CST 2015


On Wed, Dec 16, 2015 at 7:10 AM, Donnacha Oisín Kidney <
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?)
>
> 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?

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/20151216/512e9168/attachment.html>


More information about the swift-evolution mailing list