Fork me on GitHub
Timo Freiberg11:12:08

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

Timo Freiberg11:12:39

my pre-specter implementation just uses (update-in tree [:field1 field1-val ...] (fnil conj #{}) key-of-entity)

Timo Freiberg11:12:49

so in the end i get a big map like

{:field1 {"1" {:field2 {nil {:field3 {"B" {..}}}}}
          "2" {:field2 {nil {:field3 {"C" {..}}}}}}}

Timo Freiberg11:12:46

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

Timo Freiberg11:12:58

i already replaced nil with a :empty, that solved that problem

Timo Freiberg11:12:27

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

Timo Freiberg12:12:33

maybe someone can help me with this problem or confirm that specter doesn't use nil or hashmaps/hashsets as map keys in setval?

Timo Freiberg12:12:09


(S/setval [:field1 "1"
           :field2 :empty
           :field3 "A"
           :field4 (S/multi-path
                    #{:a :b}
                    {:a #{:b :c}})]
;; => {: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:

Timo Freiberg16:12:04

awesome, that did it