diff --git a/base/reduce.jl b/base/reduce.jl index 5b9b004d2af29..185a158893daa 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -88,6 +88,8 @@ Create a mapping reducing function `rf′(acc, x) = rf(acc, f(x))`. struct MappingRF{F, T} f::F rf::T + MappingRF(f::F, rf::T) where {F,T} = new{F,T}(f, rf) + MappingRF(::Type{f}, rf::T) where {f,T} = new{Type{f},T}(f, rf) end @inline (op::MappingRF)(acc, x) = op.rf(acc, op.f(x)) diff --git a/test/reduce.jl b/test/reduce.jl index 6cbe01a5de1cf..0876b30008f84 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -640,3 +640,6 @@ x = [j+7 for j in i] Iterators.flatten((1:2, 3:4)), ) == (1, 4) end + +# make sure we specialize on mapfoldl(::Type, ...) +@test @inferred(mapfoldl(Int, +, [1, 2, 3]; init=0)) === 6