hey everyone, i'm trying to use specter to build a tree-structure of nested maps and struggling with what kinds of values are allowed in the path in setval
my pre-specter implementation just uses (update-in tree [:field1 field1-val ...] (fnil conj #{}) key-of-entity)
so in the end i get a big map like
{:field1 {"1" {:field2 {nil {:field3 {"B" {..}}}}}
"2" {:field2 {nil {:field3 {"C" {..}}}}}}}
my problem is that some values are nil
and some values are hashmaps themselves. and specter doesn't seem to use nil
and hashmaps in the path of setval
i already replaced nil
with a :empty
, that solved that problem
but i rely on the hashmap values for equality. my current plan for a workaround is represent that data as a sorted string and hope i can get a canonical representation working
maybe someone can help me with this problem or confirm that specter doesn't use nil
or hashmaps/hashsets as map keys in setval
?
example:
(S/setval [:field1 "1"
:field2 :empty
:field3 "A"
:field4 (S/multi-path
:c
#{:a :b}
{:a #{:b :c}})]
"ID"
{})
;; => {:field1 {"1" {:field2 {:empty {:field3 {"A" {:field4 {:c "ID"}}}}}}}}
I'd like for the paths #{:a :b}
and {:a #{:b :c}}
to also be created@timo.freiberg if you want to use a map as a key, wrap it in the keypath
navigator
only basic types like keywords, strings, and numbers are automatically inferred use keypath
navigation
see this for a complete listing of navigators available to you: https://github.com/nathanmarz/specter/wiki/Cheat-Sheet
awesome, that did it