Fork me on GitHub
#beginners
<
2023-02-13
>
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

rolt08:02:42

defmethod f :default

馃檶 1
rolt08:02:00

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

M J08:02:10

What do you mean?

rolt08:02:43

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))