reduce(op, itr)

reduce(op, itr)

Like reduce(op, v0, itr). This cannot be used with empty collections, except for some special cases (e.g. when op is one of +, *, max, min, &, |) when Julia can determine the neutral element of op.

Examples

julia> reduce(*, [1,2,3,4,5])       
120
julia> reduce(+, 10, [1,2,3,4,5])   
25

julia> reduce(-, 1:5) -13

julia> reduce(+, 1:5) 15

Reducing using a function

julia>  function foo (x,y)
            x+y+2
        end
julia> reduce(foo, 10, [1,2,3,4,5])
35

See Also

append!, delete!, deleteat!, empty!, endof, filter, filter!, gc, get!, getkey, haskey, insert!, isempty, keys, map, map!, merge, merge!, pop!, prepend!, push!, reduce, resize!, shift!, splice!, unshift!, values,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: