Fork me on GitHub
#malli
<
2021-08-10
>
Joel03:08:36

I would think ':b' could be in square brackets: [:a {:x "s"} [:b]], but it doesn't work, i'd like to be able to nest :cat/n

(-> [:cat
       [:enum :a]
       [:map [:x string?]]
       [:cat [:enum :b]]]
      (mc/explain
        [:a {:x "s"} :b])
      (me/humanize))

ikitommi04:08:05

@joel380 from the README:

As all these examples show, the "seqex" operators take any non-seqex child schema to mean a sequence of one element that matches that schema. To force that behaviour for a seqex child :schema can be used:

(m/validate
  [:cat [:= :names] [:schema [:* string?]] [:= :nums] [:schema [:* number?]]]
  [:names ["a" "b"] :nums [1 2 3]])
; => true

;; whereas
(m/validate
  [:cat [:= :names] [:* string?] [:= :nums] [:* number?]]
  [:names "a" "b" :nums 1 2 3]) 
; => true

馃憤 2
ikitommi04:08:53

e.g.

[:cat
 [:enum :a]
 [:map [:x string?]]
 [:schema [:cat [:enum :b]]]]

ikitommi05:08:41

@emccue fixed in master. Also, you don鈥檛 need the malli.instrument/collect!, malli.dev/start! calls that.

emccue12:08:32

But it won't call it on reload if i'm using the metadata form for the schema right?

ikitommi13:08:34

currently only on start!. I tried to add var-watching to the once-registered vars, but didn't have the skills to do that. start! & stop! should play nice with reloaded repl thou.

Darnaroth Darnarowth12:08:22

Question, is it possible to add sci options on a custom decoder, or any ability to set sci options globally?

Karol W贸jcik12:08:42

Hi! How can I check if x satisfies the protocol y in malli metadata schema?

Karol W贸jcik13:08:30

Ok I found the answer!

amithgeorge07:12:11

I found this thread via Slack search. Please share the answer!!

Karol W贸jcik14:12:11

Create a schema from a -simple-schema

(def proto-schema (-simple-schema {:pred (fn [x] (satisfies? PROTO x)}))

amithgeorge14:12:41

Thank you! Will try this. :thumbsup:

ikitommi13:08:34

currently only on start!. I tried to add var-watching to the once-registered vars, but didn't have the skills to do that. start! & stop! should play nice with reloaded repl thou.

ikitommi13:08:12

silly-hacky-var-watching-diy-horror:

(defn plus1
  "adds 1 to number"
  {:malli/schma [:=> [:cat :int] :int]}
  [x] (inc x))

(add-watch #'plus1 ::watch (fn [_ v _ _] (future (println v "=>" (-> v meta :malli/schema)))))

(defn plus1
  "adds 1 to number"
  {:malli/schema [:=> [:cat [:int {:min 0}]] :int]}
  [x] (inc x))
; =prints=> #'user/plus1 => [:=> [:cat [:int {:min 0}]] :int]

ikitommi13:08:48

if that could be made robust, could just re-define schmatized vars and the clj-kondo + instrumentation would follow instantly.

ikitommi13:08:03

ideas welcome (asked on #clojure too)

emccue14:08:20

well, if it needs to be "scheduled to fetch later" you could have something like

emccue14:08:09

(defn schedule-to-refresh 
  [var]
  (set! some-flag-another-thread-is-waiting-on true)
  ;; Or
  (.push some-array-blocking-queue-another-thread-is-waiting-on ...))

(add-watch #'plus1 
  (fn [_ v _ _]
    (schedule-to-refresh v)))

馃憣 2
emccue14:08:09

so at least you don't necessarily interact with the future threadpool

emccue14:08:23

and it isn't a race condition

robert-stuttaford16:08:29

@ikitommi thanks for the humanize buffs 馃檪

馃憤 2