Fork me on GitHub
#clojure-russia
<
2019-01-04
>
pavetok09:01:22

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

(defprotocol Foo
  (foo [_]))

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

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

kuzmin_m09:01:54

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.

pavetok10:01:08

спасибо

prepor11:01:06

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

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

👍 5