Accumulate with init

Just noticed that accumulate does not include its init value in the output vector. What is the reason for that choice?

Including init would be handy for cases like:

v = rand(10)
accumulate(+, diff(v); init = v[1])

It would also match scanl in Haskell. There it’s motivated as scanl f e = map (foldl f e) . inits where inits computes all prefixes (starting with the empty one).

Ok, have checked a few more languages and there does not seem to be much consistency:

  • Inluding init: Haskell scanl, Clojure reductions, R Reduce with accumulate = T

  • Excluding init: Rust scan, Julia accumulate, J F:.