[swift-evolution] [swift-evolution-announce] [Review] SE-0045: Add scan, prefix(while:), drop(while:), and iterate to the stdlib
kevin at sb.org
Fri Apr 29 16:56:29 CDT 2016
On Thu, Apr 28, 2016, at 12:30 PM, Mark Lacey via swift-evolution wrote:
> I haven’t read through the complete proposal in detail, but regarding
> the ‘scan’ operation I would like to point out that the definition
> given in the example matches the semantics of what is usually called
> ‘prescan' or 'exclusive scan', whereas ‘scan’ (aka ‘inclusive scan’ or
> ‘prefix sum’) would not include the identity element, and each
> position of the result would include applying the operator to the
> elements up to and including the element in the same position of the
> source array, e.g.:
> (1..<6).scan(combine: +) // [1, 3, 6, 10, 15, 21]
Interesting, I was not aware of the distinction here. The `scan` method
as proposed here matches the behavior of Haskell's `scanl` method
I'm in favor of keeping the behavior as-is, because the "inclusive scan"
behavior can be recovered trivially by calling `.dropFirst()` on the
resulting sequence, whereas recovering prescan from inclusive scan is
not so trivial.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution