ClojureDocs

Nav

Namespaces

prefer-method

clojure.core

Available since 1.0 (source)
  • (prefer-method multifn dispatch-val-x dispatch-val-y)
Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y 
 when there is a conflict
1 Example
(def m {:os ::osx})

(defmulti ex :os)

(defmethod ex ::unix
 [_]
 "unix")

(derive ::osx ::unix)

(ex m)
;;=> "unix"

(defmethod ex ::bsd
  [_]
  "bsd")

(derive ::osx ::bsd)

;; which one to choose ::unix or ::bsd ?? -> Conflict!!!
(ex m)
;;=> IllegalArgumentException Multiple methods in multimethod 'ex' match...

(prefer-method ex ::unix ::bsd)

(ex m)
;;=> "unix"

See Also

Given a multimethod, returns a map of preferred value -> set of other values

Added by abrooks

Given a multimethod and a dispatch value, returns the dispatch fn that would apply to that value, ...

Added by abrooks

Given a multimethod, returns a map of dispatch values -> dispatch fns

Added by abrooks
0 Notes
No notes for prefer-method