+1 There are many things that I would like more but this is a reasonable compromise.
On Mon, May 1, 2017 at 8:02 PM, Nevin Brackett-Rozinsky via swift-evolution <[email protected]> wrote: > Another possibility is to make “map” generic on the return type, something > like: > > extension Collection { > func map<T: RangeReplaceableCollection> (transform: (Iterator.Element) > throws -> T.Iterator.Element) rethrows -> T { > var result = T() > for e in self { try result.append(transform(e)) } > return result > } > } > > That way the user can choose what type they want. And since there is also > a more-specific implementation returning an Array, that is what you’ll get > if context does not constrain the type, so existing code will still work > the same. > > We could do the same for “filter”, in which case the current proposal > would just change what the default type is. So…what I’m talking about here > would be purely additive and can happen later. > > In any case, I do like the idea being proposed in SE–0174. If I have a > collection and I filter it down, it makes sense to still be the same kind > of collection. So, +1 from me. > > Nevin > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution > >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
