This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-02
Channels
- # asami (24)
- # babashka (85)
- # beginners (137)
- # calva (46)
- # cider (16)
- # clj-kondo (19)
- # cljs-dev (7)
- # clojure (13)
- # clojure-australia (1)
- # clojure-europe (10)
- # clojure-nl (4)
- # clojure-spec (6)
- # clojure-uk (3)
- # clojurescript (5)
- # conjure (21)
- # cursive (15)
- # datascript (46)
- # datomic (13)
- # depstar (32)
- # figwheel-main (1)
- # fulcro (6)
- # honeysql (20)
- # lsp (53)
- # malli (7)
- # meander (9)
- # off-topic (35)
- # other-languages (1)
- # polylith (41)
- # re-frame (5)
- # reagent (4)
- # releases (3)
- # rewrite-clj (2)
- # shadow-cljs (22)
- # spacemacs (15)
- # tools-deps (3)
- # xtdb (17)
I am wondering how Malli is performing in an inheritance-like scenario. Essentially, Malli allows keys to be :optional
in :map
. This is about having whole sets of keys being optional, in an all-or-none fashion, such as:
(def AnimalBase
[:map ...])
(def Cat
[:merge
AnimalBase
[:map ...]])
(def Dog
[:merge
AnimalBase
[:map ...]])
(def Animal
(m/schema [:multi {:dispatch :type-or-something} :cat Cat :dog Dog]))
Does it leverage the fact that the AnimalBase
schema is mandatory in all dispatched schemas?
Is there maybe an already existing better way of representing inheritance? Also assuming that being able to use generation is mandatory.:merge
with two map schemas creates a new map schema with keys from both schemas, so Cat and Dog don't refer to AnimalBase but are instead just map schemas with properties from the inputs
Or hmph, I might be confusing it with malli.util/merge
... not sure if this works similarly
:merge
should same as malli.util/merge
I believe malli.util/merge
is indeed eager in that sense (creating a new map schema and forgetting about AnimalBase
). But theoretically, since this example relies on data and :merge
, that :multi
schema could deduce that all dispatched schemas are maps that could have a common set of keys.
But it is just the most straightforward way of representing single inheritance IMO, maybe there is something better.
Sorry I realized my example was a bit misleading so I deleted it so it doesn't spam the channel. I'll work more on this and try to come back with a real-world one.