get-method

clojure.core

  • (get-method multifn dispatch-val)
Given a multimethod and a dispatch value, returns the dispatch fn
that would apply to that value, or nil if none apply and no default

1 Example top

  • ;; define a multi-method, then demonstrate that you may use 
    ;; get-method in the same way you can call the method directly
    
    user=> (defmulti tos :Ob)
    #'user/tos
    user=> (defn line [p1 p2] {:Ob :line :p1 p1 :p2 p2})
    #'user/line
    user=> (defn circle [cent rad] {:Ob :circle :cent cent :rad rad})
    #'user/circle
    user=> (defmethod tos :line [l] (str "Line:" (l :p1) (l :p2)))
    #<MultiFn clojure.lang.MultiFn@a0b1cd0>
    user=> (defmethod tos :circle [c] (str "Circle:" (c :cent) (c :rad)))
    #<MultiFn clojure.lang.MultiFn@a0b1cd0>
    user=> (println (tos (circle [2 3] 3.3)))
    Circle:[2 3]3.3
    nil
    user=> (println (tos (line [1 1][0 0])))
    Line:[1 1][0 0]
    nil
    user=> (println ((get-method tos :line) (line [1 2][3 4]) ))
    Line:[1 2][3 4]
    nil
    user=>
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1643 top

(defn get-method
  "Given a multimethod and a dispatch value, returns the dispatch fn
  that would apply to that value, or nil if none apply and no default"
  {:added "1.0"
   :static true}
  [^clojure.lang.MultiFn multifn dispatch-val] (.getMethod multifn dispatch-val))
Vars in clojure.core/get-method:
Used in 0 other vars

Comments top

No comments for get-method. Log in to add a comment.