[swift-evolution] Reduce with inout
ben_cohen at apple.com
Tue Jan 17 15:55:41 CST 2017
> On Jan 16, 2017, at 5:49 AM, Chris Eidhof via swift-evolution <swift-evolution at swift.org> wrote:
> How does everyone feel about adding a second version of `reduce` to `Sequence`? Instead of a `combine` function that's of type `(A, Element) -> A`, it would be `(inout A, Element) -> ()`. This way, we can write nice functionals algorithms, but have the benefits of inout (mutation within the function, and hopefully some copy eliminations).
> IIRC, Loïc Lecrenier first asked this on Twitter. I've been using it ever since, because it can really improve readability (the possible performance gain is nice, too).
> Here's `reduce` with an `inout` parameter, including a sample: https://gist.github.com/chriseidhof/fd3e9aa621569752d1b04230f92969d7 <https://gist.github.com/chriseidhof/fd3e9aa621569752d1b04230f92969d7>
> Chris Eidhof
> swift-evolution mailing list
> swift-evolution at swift.org
Instead of a filter reimplementation for the proposal, might be good to do something that doesn’t exist this would be useful for, like a version of Unix uniq that filters adjacent equal entries.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution