This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-12
Channels
- # adventofcode (1)
- # announcements (1)
- # atom-editor (4)
- # aws (4)
- # babashka (7)
- # beginners (46)
- # biff (14)
- # calva (11)
- # cljdoc (2)
- # clojure (78)
- # clojure-art (1)
- # clojure-austin (1)
- # clojure-europe (50)
- # clojure-nl (2)
- # clojure-norway (22)
- # clojure-spec (2)
- # clojure-uk (2)
- # clojurescript (72)
- # conjure (6)
- # core-typed (6)
- # eastwood (4)
- # events (1)
- # figwheel-main (11)
- # fulcro (1)
- # guix (1)
- # helix (13)
- # jobs (2)
- # jobs-discuss (4)
- # kaocha (2)
- # malli (5)
- # off-topic (7)
- # pathom (22)
- # pedestal (9)
- # re-frame (29)
- # reagent (7)
- # releases (2)
- # remote-jobs (1)
- # rewrite-clj (12)
- # shadow-cljs (44)
- # sql (13)
- # squint (2)
- # xtdb (17)
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? https://github.com/typedclojure/typedclojure/blob/fdfbaa45f5e54118db72c4f3b4babb537421f518/typed/clj.checker/src/typed/clj/checker/assoc_utils.clj#L181