clojure-russia

Работа и релокейт: #jobs-rus | #clojure-russia-offtop Телеграм-чат https://t.me/clojure_ru
pavetok 2019-01-04T09:43:22.209700Z

привет, можно как-то такое починить?

(defprotocol Foo
  (foo [_]))

(extend-protocol Foo
  IMapEntry
  (foo [_]
    "IMapEntry")
  IPersistentVector
  (foo [_]
    "IPersistentVector"))

(comment
  (foo (first {:a :b}))) => "IPersistentVector"

kuzmin_m 2019-01-04T09:48:54.210Z

You can implement a protocol on an interface

this is primarily to facilitate interop with the host (e.g. Java)

but opens the door to incidental multiple inheritance of implementation

since a class can inherit from more than one interface, both of which implement the protocol

if one interface is derived from the other, the more derived is used, else which one is used is unspecified.

kuzmin_m 2019-01-04T09:48:58.210200Z

https://clojure.org/reference/protocols

kuzmin_m 2019-01-04T09:49:33.210500Z

@pavetok

pavetok 2019-01-04T10:45:08.210600Z

спасибо

prepor 2019-01-04T11:16:06.211400Z

@pavetok возможно, такой вариант вполне устроит:

(extend-protocol Foo
  MapEntry
  (foo [_]
    "MapEntry")
  IPersistentVector
  (foo [_]
    "IPersistentVector"))

👍 1
kuzmin_m 2019-01-04T17:29:46.211700Z

https://www.youtube.com/watch?v=vbGbXUjlRyQ