[swift-dev] What to do with the rest of SE-0174?

Gmail david.ronnqvist at gmail.com
Thu Jul 20 04:12:44 CDT 2017


Hi.

I was looking to implement SE-0174 <https://github.com/apple/swift-evolution/blob/master/proposals/0174-filter-range-replaceable.md> (Change filter to return an associated type) but noticed that a different RangeReplaceableCollection.filter implementation had already been added in fd2ac31 to make String.filter return a String.

The RangeReplaceableCollection.filter implementation in SE-0174 eagerly enumerates self to filter its elements:

var result = Self()    
for element in self {        
    if try isIncluded(element) {
        result.append(element)
    }
}   
return result

whereas the current implementation creates Self from a lazy filter:
 
return try Self(self.lazy.filter(isIncluded))

Which of these implementations is preferred for SE-0174?

The intended behavior of SE-0174 is already there with Data, Set, String, etc. returning Self when filtered. As far as I can tell the only remaining work is to add the associated type and specify the type alias in a few places to disambiguate which implementation is used to satisfy the Sequence protocol, essentially making this a non functional change. Or am I missing something? 

Regards,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170720/00104223/attachment.html>


More information about the swift-dev mailing list