Big +1 to this. I really like the Pattern
result-builder. As you say, it's more much readable, and if it can indeed generate efficient code, it would be an obvious improvement.
That is rather unforunate. The standard library only has an eager split
; there is a lazy version in swift-algorithms
, but that's a very big package and some projects may be reluctant to add such massive dependencies. We have a lazy filter
, but it's a badly-behaved Collection which can lead to performance and code-size penalties. There is definitely room for improvement when it comes to the standard library's collection algorithms, even outside of this effort.
This looks really great. The biggest issue I see is that result-builders don't allow you to control type resolution. Adding types like "Group", "Newline", or "Repeating" to the top-level standard library seems problematic. The topic has come up several times before, though, so there is certainly interest in the community.
Is it possible for the compiler to disambiguate the result-builder from the regular contains(where:)
function we have today?
Can we do this with RangeReplaceableCollection
? It has... certain quirks, you might say (little things, like invalidating all indices whenever you mutate the collection) that make this difficult to implement generically. I'd definitely be +1 to replacing RRC itself to remedy this.
If the matches are returned as slices and then processed in bulk, using them for replacement means quadratic performance due to excessive COWs. Replacing-as-you-go can be more efficient, but only if you can stop the collection removing excess capacity until all operations are finished. IMO, that would be a critical part of an RRC replacement.