`mergewith` but for `NamedTuple`?

julia> a = (;x=3); b = (; x=4);

julia> a .+ b
ERROR: ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reserved
Stacktrace:
 [1] broadcastable(::@NamedTuple{x::Int64})
   @ Base.Broadcast ./broadcast.jl:713
 [2] broadcasted(::typeof(+), ::@NamedTuple{x::Int64}, ::@NamedTuple{x::Int64})
   @ Base.Broadcast ./broadcast.jl:1328
 [3] top-level scope
   @ REPL[2]:1

julia> merge(a,b)
(x = 4,)

julia> mergewith(+, a,b)
ERROR: MethodError: no method matching mergewith(::typeof(+), ::@NamedTuple{x::Int64}, ::@NamedTuple{x::Int64})
The function `mergewith` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  mergewith(::Any)
   @ Base abstractdict.jl:403
  mergewith(::Any, ::AbstractDict, ::AbstractDict...)
   @ Base abstractdict.jl:401

Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

Exactly a year… implement mergewith(combine, ::NamedTuple, ...) by aplavin · Pull Request #53558 · JuliaLang/julia · GitHub

2 Likes