defmulti

macrosince v0.0-927 clojure.core/defmultiEdit
(defmulti name docstring? attr-map? dispatch-fn & options)

Source docstring:
Creates a new multimethod with the associated dispatch function.
The docstring and attribute-map are optional.

Options are key-value pairs and may be one of:
  :default    the default dispatch value, defaults to :default
  :hierarchy  the isa? hierarchy to use for dispatching
              defaults to the global hierarchy
Source code @ clojurescript:src/main/clojure/cljs/core.cljc
(core/defmacro defmulti
  {:arglists '([name docstring? attr-map? dispatch-fn & options])}
  [mm-name & options]
  (core/let [docstring   (if (core/string? (first options))
                           (first options)
                           nil)
             options     (if (core/string? (first options))
                           (next options)
                           options)
             m           (if (map? (first options))
                           (first options)
                           {})
             options     (if (map? (first options))
                           (next options)
                           options)
             dispatch-fn (first options)
             options     (next options)
             m           (if docstring
                           (assoc m :doc docstring)
                           m)
             m           (if (meta mm-name)
                           (conj (meta mm-name) m)
                           m)
             mm-ns (core/-> &env :ns :name core/str)]
    (core/when (= (count options) 1)
      (throw
        #?(:clj (Exception. "The syntax for defmulti has changed. Example: (defmulti name dispatch-fn :default dispatch-value)")
           :cljs (js/Error. "The syntax for defmulti has changed. Example: (defmulti name dispatch-fn :default dispatch-value)"))))
    (core/let [options (apply core/hash-map options)
               default (core/get options :default :default)]
      (check-valid-options options :default :hierarchy)
      `(defonce ~(with-meta mm-name m)
         (let [method-table# (atom {})
               prefer-table# (atom {})
               method-cache# (atom {})
               cached-hierarchy# (atom {})
               hierarchy# (cljs.core/get ~options :hierarchy ((~'js* "cljs.core.get_global_hierarchy")))]
           (cljs.core/MultiFn. (cljs.core/symbol ~mm-ns ~(name mm-name)) ~dispatch-fn ~default hierarchy#
             method-table# prefer-table# method-cache# cached-hierarchy#))))))