julia icon indicating copy to clipboard operation
julia copied to clipboard

implement mergewith(combine, ::NamedTuple, ...)

Open aplavin opened this issue 1 year ago • 9 comments

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.

aplavin avatar Mar 02 '24 17:03 aplavin

bump

aplavin avatar Apr 08 '24 08:04 aplavin

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.

jariji avatar Apr 12 '24 02:04 jariji

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.

aplavin avatar Apr 12 '24 09:04 aplavin

another bump...

aplavin avatar Apr 18 '24 18:04 aplavin

yet another bump

aplavin avatar Apr 30 '24 01:04 aplavin

yet yet another bump...

aplavin avatar May 16 '24 12:05 aplavin

yet yet yet another bump...

aplavin avatar Jun 05 '24 13:06 aplavin

yet yet yet yet another bump...

aplavin avatar Jun 30 '24 20:06 aplavin

monthly bump...

aplavin avatar Aug 01 '24 22:08 aplavin

another monthly bump...

aplavin avatar Aug 30 '24 01:08 aplavin