specter

Latest version: 1.1.3
2018-12-14T11:52:08.003500Z

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

2018-12-14T11:53:39.005Z

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

2018-12-14T11:55:49.006Z

so in the end i get a big map like

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

2018-12-14T11:56:46.006900Z

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

2018-12-14T11:56:58.007300Z

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

2018-12-14T11:58:27.008800Z

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

2018-12-14T12:00:33.010Z

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

2018-12-14T12:04:09.011100Z

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

nathanmarz 2018-12-14T15:33:16.011700Z

@timo.freiberg if you want to use a map as a key, wrap it in the keypath navigator

nathanmarz 2018-12-14T15:33:50.012400Z

only basic types like keywords, strings, and numbers are automatically inferred use keypath navigation

nathanmarz 2018-12-14T15:34:01.012700Z

see this for a complete listing of navigators available to you: https://github.com/nathanmarz/specter/wiki/Cheat-Sheet

2018-12-14T16:02:04.013Z

awesome, that did it