Hi Clojurists,
I’m trying an idea to have a flat map instead of nested maps to store / pass data and I hit one interesting problem that I’ve never had with nested maps.
I have code like this:
(ns myapp.something.foo)
(defn get-foo [a b c]
{::aaa (+ a b)
::bbb (+ a c)
::ccc (+ b c)})
(ns myapp.something.bar)
(defn get-foo [a b c]
{::aaa (+ a b)
::bbb (+ a c)
::ccc (+ b c)})
(ns myapp.something)
(require '[myapp.something.foo :as foo])
(require '[myapp.something.bar :as bar])
(defn get-foobar [a b c]
(merge
(foo/get-foo a b c)
(bar/get-foo a b c)))
(get-foobar 1 2 3)
; {:myapp.something.foo/aaa 3
; :myapp.something.foo/bbb 4
; :myapp.something.foo/ccc 5
; :myapp.something.bar/aaa 3
; :myapp.something.bar/bbb 4
; :myapp.something.bar/ccc 5}
And as you can see, implementation of get-foo
looks same and returns different output since all keywords are namespaced. If I didn’t want to namespace the keywords, I would have only one get-foo
implementation and I wonder how to make only one implementation for this example. The obvious would be to add 3 functions get-aaa
, get-bbb
, get-ccc
but I hope there is a better option.
Thank you.
Adam