Fork me on GitHub
#clojure-dev
<
2016-10-24
>
mpenet18:10:30

is it working as intended that extend of a protocol function on a record (not inline) resets all other functions in that protocol for that type?

mpenet18:10:59

(defprotocol IFoo (a [x] ) (b [x] ))
(defrecord Foo [])
(extend-protocol IFoo Foo (a [x] "A") (b [x] "B"))
(def foo (Foo.))
(extend-protocol IFoo Foo (b [x] "BB"))
(a foo) => CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context
(b foo) => "BB"

mpenet18:10:05

I know I can just split that into diff protocols, but in that particular case that's 20 protos ...

mpenet18:10:29

(it's for a Codec thing, convert from type x to y etc)

mpenet18:10:01

or I can use extend and mixin maps

dm318:10:27

protocol has a map of type -> fns

mpenet18:10:50

yeah, but that's an impl detail

mpenet18:10:58

not sure I want to rely on this

dm319:10:24

yeah, just meant that currently the extend-protocol overrides the whole type every time it's called

dm319:10:11

I'd think it's supposed to work this way

mpenet19:10:09

well the word "extend" meant something else for me, but anyway, I ll find a workaround

alexmiller19:10:16

yes, it’s supposed to work that way