Fork me on GitHub
#malli
<
2022-03-24
>
Carlo01:03:57

two follow-up questions: is there a built-in way to (mi/check) only one function? Is there a way to pretty-print the result of (mi/check)?

Carlo10:03:38

To check just one function from emacs, I ended up doing:

(defun med/cider-eval-on-top-level-form (fn-str)
  (let ((quoted-defn (concat "'" (cider-defun-at-point))))
    (cider-interactive-eval (concat "(" fn-str " " quoted-defn ")"))))

(defun malli-check-this ()
  (interactive)
  (med/cider-eval-on-top-level-form
   "#(mi/check {:filters [(mi/-filter-var #{(resolve (second %))})]})"))

Carlo12:03:53

About the (mi/check) pretty-printing issue, I ended up coding my visualization for #portal that looks like this (it happens when I issue the mi/check command, that I bound to a key):

❤️ 2
ikitommi13:03:04

Look great! There is malli.dev.pretty for pretty printing things. Could add a handler for check there

Carlo13:03:43

Thank you! Mostly, the question I had while doing this was, is there a malli spec for the kind of errors that are generated by (mi/check)? I temporarily shimmed it as:

(def check-error
  (m/schema
   [:map-of symbol? [:map
                     [:errors [:sequential
                               [:map
                                [:check [:map
                                         [:malli.generator/explain-output :any]]]]]]]])) 
but maybe you have something more complete. Btw, I'm really liking malli, it's really well designed! 😍

ikitommi14:03:18

thanks! there is no schema for it, but could be, PR welcome.

rovanion16:03:03

Is the following untrue because what's compared is just the addresses in the references?

(deftest optionalize-db-generated-keys
  (= (malli.util/optional-keys [:map [:key [:int]]])
     (malli/schema [:map [:key {:optional true} [:int]]])))

ikitommi16:03:43

Recall there is mu/equals, using just form checking. Could be improved...

Carlo16:03:22

I asked this quite some time ago, and IIRC at the time it wasn't possible: what's the way of writing a spec for the function (defn add [x y] ...) so that we check that the result is bigger than both x and y?

Carlo17:03:57

@U055NJ5CC I see that https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L2443-L2445 is the place in which the function is instrumented, and that's probably where a check for the new :fn key of :=> should go. But what else should be changed?