malli

https://github.com/metosin/malli :malli:
ikitommi 2020-06-22T07:02:39.115700Z

About recursive schemas. It seems that because of those, should to to add a (-children [this]) method into Schema protocol. Why? Currently, there is generic children function that returns the Schema AST for the children. The AST is unaware of any instance bindings such as local recursion targets. Given a Schema:

[:maybe {:id :cons}
   [:tuple int? [:ref :cons]]]
, the generator for :tuple just sees children of (int? [:ref :cons])and doesn’t know what :cons refers to and fails.

ikitommi 2020-06-22T07:05:27.118100Z

We could hack around this by pulling out options that created :tuple and using those to re-create the child schemas, providing all the needed local context. But, this is error-prone as one needs to wire-up all generators, visitors etc. using the original options from the father schema.

ikitommi 2020-06-22T07:05:58.118600Z

(currently passing the local context via options, which seems to be a good way to do it)

ikitommi 2020-06-22T07:06:14.118900Z

Anyway, this works now:

ikitommi 2020-06-22T07:06:24.119Z

ikitommi 2020-06-22T07:07:59.120600Z

with recursion, one can set the recursion limit, just like with spec. One setting, but each :ref is counted separatly, defaulting to 10.

ikitommi 2020-06-22T07:58:20.120900Z

wrote more to the recursion issue, comments welcome: https://github.com/metosin/malli/pull/117#issuecomment-647348039

2020-06-22T14:06:47.121300Z

I feel that having more than 1 way of defining recursive structures implies that users will have to choose which to use. Choice can sometimes be a problem more than a solution.

👀 1