Fork me on GitHub
#cljs-dev
<
2022-09-08
>
Lidor Cohen13:09:49

Hello everyone 🙂 , what is the reason that merge, select-keys, etc. are not part of a protocol?

bronsa13:09:36

why would they be? they build on more primitive functions that are part of protocols

Lidor Cohen13:09:18

Good question, the use-case I encountered is in implementing some kind of lazy-map and I wanted to implement all the relevant interfaces so that all the functions on regular map would work and be kept in the same "lazy" domain, i.e: (merge lazy-map1 lazy-map2) => lazy-map3

Lidor Cohen13:09:08

but select-keys for example, explicitly constructs a map {} within it, so there's no way to override this with a protocol implementation.

bronsa14:09:03

sounds like you should go the other way

bronsa14:09:21

define your own polymorphic select-keys and use c.c/select-keys as the default impl

Lidor Cohen14:09:56

Yeah that's what I did

Lidor Cohen14:09:49

Thanks 🙏:skin-tone-3:

Lidor Cohen14:09:45

But my question was honest, I saw the implementation and thought that it could go in some map protocol. I think it still can be patched with no breaking changes, that's why I asked if there was a specific reason it wasn't done, is there some intentional design decision behind it? And if there isn't, can I submit a patch for it?

mikerod00:09:17

Seems like empty could be used for it to be polymorphic too. But haven't looked much.

bronsa12:09:57

usually core protocols denote primitive functionality, select-keys is not such. I can see an argument why merge may be

Lidor Cohen13:09:33

@U060FKQPN I agree, if select-keys can be implemented on top of more primitive protocols that given an implementation would keep the structure in the source type that's the way it should be. Another aspect to consider: clojure/script never made the commitment that data structures would keep their original type after transformations, iiuc, mostly due to laziness.

Lidor Cohen13:09:23

Does anyone know where can I ask about this suggestion \ contribution?

Lidor Cohen07:09:56

@U050B88UR maybe you can help me here? how can I promote reimplementing map functions (currently I observed only select-keys & merge) based only on protocol functions? Or, if I can't, (perhaps because there's a reason for them to be implemented that way) you can shed more light and I can become a better clojurian 😅