Skip to content

Commit eae9a54

Browse files
committed
fixes based on @TotalVerb's comments
1 parent 69114af commit eae9a54

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/reduce.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ reduce_empty(op, T) = _empty_reduce_error()
259259
reduce_empty(::typeof(+), T) = zero(T)
260260
reduce_empty(::typeof(+), ::Type{Bool}) = zero(Int)
261261
reduce_empty(::typeof(*), T) = one(T)
262+
reduce_empty(::typeof(*), ::Type{Char}) = ""
262263
reduce_empty(::typeof(&), ::Type{Bool}) = true
263264
reduce_empty(::typeof(|), ::Type{Bool}) = false
264265

@@ -303,6 +304,7 @@ The default is `x`.
303304
"""
304305
reduce_single(op, x) = x
305306
reduce_single(::typeof(+), x::Bool) = Int(x)
307+
reduce_single(::typeof(*), x::Char) = string(x)
306308

307309
reduce_single(::typeof(add_sum), x) = reduce_single(+, x)
308310
reduce_single(::typeof(add_sum), x::SmallSigned) = Int(x)
@@ -489,7 +491,7 @@ function mapreduce_impl(f, op::Union{typeof(scalarmax),
489491
A::AbstractArray, first::Int, last::Int)
490492
# locate the first non NaN number
491493
@inbounds a1 = A[first]
492-
v = f(a1)
494+
v = mapreduce_single(f, op, a1)
493495
i = first + 1
494496
while (v == v) && (i <= last)
495497
@inbounds ai = A[i]

test/reduce.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,8 @@ test18695(r) = sum( t^2 for t in r )
391391
# test neutral element not picked incorrectly for &, |
392392
@test @inferred(foldl(&, Int[1])) === 1
393393
@test_throws ArgumentError foldl(&, Int[])
394+
395+
# prod on Chars
396+
@test prod(Char[]) == ""
397+
@test prod(Char['a']) == "a"
398+
@test prod(Char['a','b']) == "ab"

0 commit comments

Comments
 (0)