Fork me on GitHub
Francesco Arena16:09:01

Hi everyone, I just started playing with typed clojure and I mostly studied from the wiki section of the old repo core.typed. I have a question about HMaps: is there a way to "merge" 2 (or more) hmaps to obtain a new one? In other words, is there a function mergeHmap that works like this:

(t/defalias A (t/HMap :mandatory {:a String :b Integer}))
(t/defalias B (t/HMap :mandatory {:c String}))
(t/defalias AB (mergeHmap A B)) ; => (t/HMap :mandatory {:a String :b Integer :c String})
My problem is: let's say we have two HMaps with several mandatory keys. It would be nice to have an easy way to obtain a "merged" version. Thanks for the help!


Hi @U03CEA0LVHP, this isn't exposed, but you might try intersecting them with t/I. It's different than a merge though, it results in a type that is "both" maps. Merging functionality is probably exposed in the internals, could be exposed as something like t/Merge perhaps.


looks like there's dissoc, assoc, and get implemented internally, but not merge. Would be cool to have. There's a helper to merge two HMap's, I wonder how much more is needed?


Oh, that must be the support for type checking clojure.core/merge calls.


Maybe we can just reify that as a type. Might not need any subtyping rules in the common case. If we can expand it to another HMap, it should just work.


released in 1.0.32 as t/Merge.