<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Thu, Apr 28, 2016, at 12:30 PM, Mark Lacey via swift-evolution wrote:<br></div>
<blockquote type="cite"><div>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.:<br></div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;<span class="highlight" style="background-color:rgb(247, 247, 247)"><span class="colour" style="color:rgb(150, 152, 150)"><span class="font" style="font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace"><span class="size" style="font-size:14px">(1..&lt;6).scan(combine: +) // [1, 3, 6, 10, 15, 21]</span></span></span></span><br></div>
<div>&nbsp;</div>
<div>Sources:<br></div>
<div>&nbsp;&nbsp;<a href="https://www.cs.cmu.edu/~guyb/papers/Ble93.pdf">https://www.cs.cmu.edu/~guyb/papers/Ble93.pdf</a><br></div>
<div> <a href="https://en.wikipedia.org/wiki/Prefix_sum">https://en.wikipedia.org/wiki/Prefix_sum</a><br></div>
</blockquote><div>&nbsp;</div>
<div>Interesting, I was not aware of the distinction here. The `scan` method as proposed here matches the behavior of Haskell's `scanl` method (<a href="http://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html#v:scanl">http://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html#v:scanl</a>).<br></div>
<div>&nbsp;</div>
<div>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.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard</div>
</body>
</html>