# Accumulate with init

**URL:** https://discourse.julialang.org/t/accumulate-with-init/121266
**Category:** General Usage
**Tags:** question
**Created:** [October 13, 2024, 10:00pm UTC](https://discourse.julialang.org/t/accumulate-with-init/121266 "2024-10-13T22:00:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)
#### Post date: [October 13, 2024, 10:00pm UTC](https://discourse.julialang.org/t/accumulate-with-init/121266/1 "2024-10-13T22:00:06Z")

</div>

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:

```julia
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).

---

<div class="post-metadata">

### Author: ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)
#### Post date: [October 13, 2024, 11:04pm UTC](https://discourse.julialang.org/t/accumulate-with-init/121266/2 "2024-10-13T23:04:41Z")

</div>

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:.`
