malli

https://github.com/metosin/malli :malli:
escherize 2021-06-17T02:07:57.169800Z

Hello, I want to build a general data-building ui, that takes a description of the datastructure as input (a malli schema, this time around). I couldn’t find much prior work in this regard. I have a half-baked prototype here: https://escherize.com/w/data-desk/ So far, that mostly works for int? string? boolean? :vector and :map and combinations of them. So do you know of anything similar?

escherize 2021-06-17T02:43:58.170500Z

As for the implementation, I’m using a local atom and this multimethod: https://github.com/escherize/data-desk/blob/main/src/data_desk/views.cljs#L37

Yehonathan Sharvit 2021-06-17T06:04:40.170700Z

Ok. Thanls

Yehonathan Sharvit 2021-06-17T06:05:27.171700Z

I'd like to validate inside a function that the function is called with valid arguments. Should I use :=> ? How exactly?

Yehonathan Sharvit 2021-06-17T09:12:06.172700Z

The readme doens't cover it

Yehonathan Sharvit 2021-06-17T12:48:54.172900Z

Here is what I am doing

Yehonathan Sharvit 2021-06-17T12:51:18.173100Z

(def =>plus [:=> [:cat int? int?] int?])

(defn plus [x y]
  (when-not
      (m/validate (second =>plus) [x y])
    (throw (ex-info "invalid input" {})))
  (+ x y))

Yehonathan Sharvit 2021-06-17T12:51:28.173300Z

Is there a more idiomatic way?

ikitommi 2021-06-17T15:58:29.173700Z

there will be malli.instrument, while waiting, there is malli-indtrument - https://github.com/setzer22/malli-instrument

Yehonathan Sharvit 2021-06-20T07:12:35.181Z

Very cool! Any reason why it's not yet part of malli?

ikitommi 2021-06-20T07:16:04.181300Z

just time to merge & cleanup, the original issue is here: https://github.com/metosin/malli/issues/349

ikitommi 2021-06-20T07:18:54.181600Z

the function checker code shuould be reused between malli.generate and malli.instrument.

Yehonathan Sharvit 2021-06-21T07:43:01.182Z

Is someone already working on this consolidation?

ikitommi 2021-06-21T08:10:44.182200Z

please ask on the issue. on my summer backlog if no-one has time. need this too after the vacations.

Yehonathan Sharvit 2021-06-22T09:07:09.188200Z

ok. will do

ikitommi 2021-06-17T06:21:00.172200Z

README should cover that

ikitommi 2021-06-17T06:21:01.172400Z

https://github.com/metosin/malli#function-schemas

deadghost 2021-06-17T19:55:58.175200Z

Is there something I can do to make the results of mu/union more condensed?

(mu/union (mu/union nil? empty?) empty?)
=> [:or [:or nil? empty?] empty?]