weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
865 stars 66 forks source link

dissoc-in has unexpected behaviors #57

Closed c0rrzin closed 2 years ago

c0rrzin commented 2 years ago
(dissoc-in {:x {}} [:x :y])
;=> {}

Is that intended in the implementation? If not, would be happy to submit a PR.

Cheers

weavejester commented 2 years ago

The result is consistent with the docstring, so I believe it is correct.

c0rrzin commented 2 years ago

Understood! Will close the issue then. I am curious though to why you chose to implement it that way - my feeling is that this needs to be explicitly explained, because it's usually not expected.

Thanks

weavejester commented 2 years ago

The dissoc-in function is designed to be the reverse of assoc-in, as far as is possible. So assoc-in will add maps if they are not found, and dissoc-in will remove them.

In the example you gave, the map is already empty. We could add a check for this, to only remove outer maps if the keys index exists. But this would add overhead to a relatively niche case, and I'm not sure it would be worth it.