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

Dave Abrahams dabrahams at apple.com
Thu Dec 17 16:20:02 CST 2015


Having discussed it with the team, I withdraw my objection to the implementation strategy.  CollectionOfZeroOrOne is an orthogonal capability that should be handled separately, if at all.

So, +1 for acceptance, provided there are tests.

> On Dec 16, 2015, at 12:14 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
> OK, maybe I need to think about this more carefully.  Sorry if I drew incorrect/hasty conclusions.
> 
>> On Dec 16, 2015, at 11:35 AM, Donnacha Oisín Kidney <oisin.kidney at gmail.com <mailto:oisin.kidney at gmail.com>> wrote:
>> 
>> Oops, sorry, I wasn’t very clear. I was just trying to compare the amount of code reuse and new types between the two versions. CollectionOfZeroOrOne would need three extensions (SequenceType, CollectionType  BidirectionalIndexType  as well as the extra struct itself. The filter version doesn’t really need a new struct, but to have a bidirectional version, you would need a LazyFilterBidirectionalCollection  which doesn’t currently exist. I had thought that that was something which may be added anyway, though.
>> 
>> Oisin.
>> 
>>> On 16 Dec 2015, at 19:08, Dave Abrahams <dabrahams at apple.com <mailto:dabrahams at apple.com>> wrote:
>>> 
>>> 
>>>> On Dec 16, 2015, at 10:15 AM, Dmitri Gribenko <gribozavr at gmail.com <mailto: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
>>> 
>>> 
>>> 
>> 
> 
> -Dave
> 
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-Dave



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


More information about the swift-evolution mailing list