Fork me on GitHub
#malli
<
2023-01-08
>
DFST02:01:47

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?

Ben Sless04:01:19

You have some schema there that models an alternative. Either alt or or?

ikitommi08:01:36

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

ikitommi08:01:53

(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

ikitommi08:01:30

there are also utilities for going from between the two, mu/path->in and mu/in->paths (could be many)

DFST15:01:12

Thanks! I'm trying to piece together something to derive different subscription and event paths for a re-frame db given my database schema. Given my pretty basic skillset, this is a bit of a stretch goal for me, but this is really helpful!

ikitommi08:01:40

:in is the path in the value (e.g. the db), did you try that?