Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Clojure multimethods only on Java classes?

I am a bit confused about whether I can only use clojure multimethods on clojure structures represented by Java classes, or can I base multimethods to dispatch on structs or other properties?

like image 584
yazz.com Avatar asked Jul 12 '26 05:07

yazz.com


1 Answers

It is very common to build multimethods that dispatch on the class of the first or only argument. In this case the "class" may be a Java class, a record (defrecord generates a Java class), or even an internal Clojure type like ISeq.

You can also dispatch on an arbitrary function of the args passed to the function. For example, you could compute a function and dispatch on a keyword if you wanted.

like image 163
Alex Miller Avatar answered Jul 16 '26 09:07

Alex Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!