Skip to content

Commit 6918213

Browse files
committed
Demonstrate init for sum and prod
1 parent 2122e0e commit 6918213

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

base/reduce.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ for non-empty collections.
520520
```jldoctest
521521
julia> sum(1:20)
522522
210
523+
524+
julia> sum(1:20; init = 0.0)
525+
210.0
523526
```
524527
"""
525528
sum(a; kw...) = sum(identity, a; kw...)
@@ -569,8 +572,11 @@ for non-empty collections.
569572
570573
# Examples
571574
```jldoctest
572-
julia> prod(1:20)
573-
2432902008176640000
575+
julia> prod(1:5)
576+
120
577+
578+
julia> prod(1:5; init = 1.0)
579+
120.0
574580
```
575581
"""
576582
prod(a; kw...) = mapreduce(identity, mul_prod, a; kw...)

0 commit comments

Comments
 (0)