3 ms·
In clojure I'd write this, if I actually needed a class for type dispatch or interface implementation for some reason. (s/defrecord Animal [name
by emidln 9y ago
In clojure I'd write this, if I actually needed a class for type dispatch or interface implementation for some reason.
(s/defrecord Animal
[name :- String
number-of-legs :- Integer])
(def dog (map->Animal
{:name "dog"
:number-of-legs 4}))
The nice thing is that I could also skip the defrecord if I just want enforcement of the shape of the data by making a similar defschema and then I'd just use plain maps.
- billrobertson42 9y agoI mucked around with records a lot early on while learning Clojure, and I'm not really sure when I stopped and just started using maps. Now it's second nature and I'd only consider using a record if there was some overriding performance concern.