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] > > Sources: > https://www.cs.cmu.edu/~guyb/papers/Ble93.pdf > https://en.wikipedia.org/wiki/Prefix_sum Interesting, I was not aware of the distinction here. The `scan` method as proposed here matches the behavior of Haskell's `scanl` method (http://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html#v:scanl) . 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. -Kevin Ballard
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
