JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

accumulate

core-api


    function
    boot.janet on line 1124, column 1

    (accumulate f init x)

    Similar to `reduce`, but accumulates successive results of applying 
    `f` into a new array. The last element in the array is what would 
    be the return value from `reduce`. The `init` value is not added 
    directly as the first value of the new array, i.e. the returned 
    array will have the same number of elements as `x`.

    `x` can be a bytes, indexed, dictionary, fiber, or abstract type 
    with suitable `get` and `next` methods.


See also:reduce2 examplesSign in to add an example
Loading...
(reduce string "ha" ["ha" "ha" "ha" "ha"]) # => "hahahahaha"

(accumulate string "ha" ["ha" "ha" "ha" "ha"]) # => @["haha" "hahaha" "hahahaha" "hahahahaha"]
jgartePlayground
(reduce     + 1 [2 3 4])  # -> 10
(accumulate + 1 [2 3 4])  # -> @[3 6 10]
cellularmitosisPlayground