JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

reduce

core-api


    function
    boot.janet on line 1087, column 1

    (reduce f init x)

    Also know as fold-left in many languages, this function transforms 
    `x` by successively applying a function `f` to values from `x` and 
    an updating "accumulator" value. `f` is a function of 2 arguments, 
    `(f acc v)`, where `acc` starts as `init` and `v` is the next value 
    in `x`. `f` returns a value that will be used as `acc` in the next 
    call to `f`. The ultimate return value is that of the final call to 
    `f`.

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


See also:accumulatereduce21 exampleSign in to add an example
Loading...
(reduce (fn [s1 s2]
          (string "[" s1 "+" s2 "]"))
        "x"
        ["a" "b" "c"])

#=> "[[[x+a]+b]+c]"
uvtcPlayground