julia
julia copied to clipboard
implement mergewith(combine, ::NamedTuple, ...)
Functionality is useful, but the previous PR https://github.com/JuliaLang/julia/pull/36291 is stale for years. This is intended as an updated modern implementation. Closes https://github.com/JuliaLang/julia/issues/36048.
Follows how merge() is defined. For now, only the @generated branch is implemented. If you think this PR can be accepted, I'll add the missing parts.
bump
Is the intended specification of mergewith(f, a, b) that it merge on keys?
Some people don't like https://github.com/JuliaLang/julia/issues/50375 but I still think it's right. This PR is consistent with the imho-regrettable keys(::NamedTuple)::Tuple{Symbol}.
If NamedTuple is supposed to behave like Tuple and mergewith works with keys then the mergewith behavior on NamedTuple is inconsistent with the behavior that mergewith would have on Tuple if that were implemented. And sure, nobody said NamedTuple is a subtype of Tuple, but imho it is in spirit, so this sort of thing just makes more of a mess out of the situation.
It's the same approach as merge(a, b) (already implemented for NT) – merges by keys. The only difference from merge is the handling of duplicate keys.
Given that merge already exists, I don't see any ambiguity regarding what mergewith should do.
another bump...
yet another bump
yet yet another bump...
yet yet yet another bump...
yet yet yet yet another bump...
monthly bump...
another monthly bump...