I'm searching for the lightest way to add a type to a clojure map I know i could use records for doing that but i'm wondering if i can do it with regular maps
i've got a function to create a map that represent a person:
(defn person [first-name last-name] {:first-name first-name :last-name last-name})
i would like to be able to do something like that:
(def wayne (person "Wayne" "Shorter"))
....
(type wayne)
=> person
You could attach some metadata:
(defn person [first-name last-name]
(with-meta {:first-name first-name :last-name last-name}
{:type 'Person}))
(def wayne (person "Wayne" "Shorter"))
(type wayne) ;; Person
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With