Fork me on GitHub
#malli
<
2021-06-17
>
escherize02:06:57

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?

escherize02:06:58

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 Sharvit06:06:27

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

ikitommi06:06:00

README should cover that

Yehonathan Sharvit09:06:06

The readme doens't cover it

Yehonathan Sharvit12:06:54

Here is what I am doing

Yehonathan Sharvit12:06:18

(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 Sharvit12:06:28

Is there a more idiomatic way?

ikitommi15:06:29

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

Yehonathan Sharvit07:06:35

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

ikitommi07:06:04

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

ikitommi07:06:54

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

Yehonathan Sharvit07:06:01

Is someone already working on this consolidation?

ikitommi08:06:44

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

deadghost19:06:58

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?]