Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dispatch a multimethod on the type of an array

Tags:

clojure

I'm working on a multimethod that needs to update a hash for a bunch of different things in a sequence. Looked fairly straitforward until I tried to enter the 'type of an array of X'.

(defmulti update-hash #(class %2))

(type (byte 1))
=> java.lang.Byte
(defmethod update-hash java.lang.Byte [md byte]
  (. md update byte))

(type (into-array  [ (byte 1)]))
=> [Ljava.lang.Byte;
(defmethod update-hash < WHAT GOES HERE > [md byte]
like image 468
Arthur Ulfeldt Avatar asked May 06 '10 16:05

Arthur Ulfeldt


1 Answers

Either of these should work:

(defmethod update-hash (Class/forName "[Ljava.lang.Byte;") [md byte] ...)

(defmethod update-hash (class (make-array Byte 0)) [md byte] ... )
like image 93
Brian Carper Avatar answered Nov 12 '22 07:11

Brian Carper