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 swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution