This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-08
Channels
- # babashka (1)
- # babashka-sci-dev (27)
- # beginners (13)
- # cljdoc (1)
- # clojure (24)
- # clojure-austin (1)
- # clojurescript (76)
- # data-science (18)
- # datomic (7)
- # java (2)
- # malli (7)
- # nbb (7)
- # off-topic (34)
- # portal (1)
- # reagent (9)
- # reitit (4)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (11)
- # squint (7)
- # tools-build (7)
- # uncomplicate (1)
This might be a basic question, but I'm a little confused about what the numbers signify in a given path that's returned by subschemas
. In the example from the readme, for example, one path that's returned is [0 :address 0 :lonlat 1]
. What are the numbers for in the vec? Is there documentation somewhere that explains how to interpret a path that I missed?
yes, each schema always accumulates to the :path
(path in schema) even if they do not contribute to the :in
(path in value). Each Schema defines it’s own meaning for :path
, but by convention, numbers represent child indexes, starting from 0. e.g.
• [:tuple :int :int]
has indexes 0 & 1
• [:maybe :int]
has just index 0
(def schema [:map [:x [:tuple :int [:maybe [:map [:y [:and :int [:> 6]]]]]]]])
(mu/subschemas schemas)
;[{:path [], :in [], :schema [:map [:x [:tuple :int [:maybe [:map [:y [:and :int [:> 6]]]]]]]]}
; {:path [:x], :in [:x], :schema [:tuple :int [:maybe [:map [:y [:and :int [:> 6]]]]]]}
; {:path [:x 0], :in [:x 0], :schema :int}
; {:path [:x 1], :in [:x 1], :schema [:maybe [:map [:y [:and :int [:> 6]]]]]}
; {:path [:x 1 0], :in [:x 1], :schema [:map [:y [:and :int [:> 6]]]]}
; {:path [:x 1 0 :y], :in [:x 1 :y], :schema [:and :int [:> 6]]}
; {:path [:x 1 0 :y 0], :in [:x 1 :y], :schema :int}
; {:path [:x 1 0 :y 1], :in [:x 1 :y], :schema [:> 6]}]
(mu/get-in schema [:x 1 0 :y])
; [:and :int [:> 6]]
(mu/get-in *1 [0])
; :int
there are also utilities for going from between the two, mu/path->in
and mu/in->paths
(could be many)