Fork me on GitHub
M J08:02:00

I am using a multimethod (demulti) that handles a couple of stuff, which for example it takes "string" or "number" and return accordingly. How do I create a method that returns something for everything else not handled? Like a default defmethod


defmethod f :default

馃檶 1

btw if you're dispatching on types you can also use protocols

M J08:02:10

What do you mean?


something like (defprotocol PrettyPrintable (pprint [this])) (extend-type String PrettyPrintable (pprint [this] (clojure.pprint/pprint this))) (syntax is probably wrong but you get the idea) instead of (defmulti pprint (fn [obj] (type obj)))

Jes煤s G贸mez12:02:22

@U02F0C62TC1 aside: type was enough, instead of (fn [obj] (type obj))