Hacker News new | ask | show | jobs
by emccue 286 days ago
One of the drawbacks about protocols mentioned in the talk is no longer correct. Protocols can now dispatch on metadata, not just type.

    (defprotocol Dog
      :extend-via-metadata true
      (bark [_]))
1 comments

Oh. Interesting. I had to look it up:

When :extend-via-metadata is true, values can extend protocols by adding metadata where keys are fully-qualified protocol function symbols and values are function implementations. Protocol implementations are checked first for direct definitions (defrecord, deftype, reify), then metadata definitions, then external extensions (extend, extend-type, extend-protocol).

(def component (with-meta {:name "db"} {`start (constantly "started")})) (start component) ;;=> "started"

Kind of a crazy feature.