This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-08
Channels
- # asami (22)
- # babashka (35)
- # beginners (4)
- # calva (76)
- # cider (7)
- # clj-on-windows (89)
- # clojure (30)
- # clojure-europe (25)
- # clojurescript (10)
- # conjure (46)
- # fulcro (13)
- # gratitude (5)
- # lambdaisland (4)
- # lsp (13)
- # malli (5)
- # membrane (6)
- # nbb (1)
- # off-topic (11)
- # re-frame (2)
- # releases (1)
- # shadow-cljs (45)
- # xtdb (4)
how do I use the function generated from :malli/gen true
in function metadata <https://github.com/metosin/malli/blob/master/docs/function-schemas.md#function-schema-metadata>?
the doc says "Setting :malli/gen
to true
while function body generation is enabled with mi/instrument!
allows body to be generated, to return valid generated data."
for example
(require '[malli.core :as m])
(defn pow
{:malli/schema [:=> [:cat :int] :int]
:malli/gen true} ; how do I find/use this generated function body?
[x]
(* x x))
(require 'malli.dev)
(malli.dev/start!)
(pow 1)
;1
You have to pass in malli.generator/generate
to the start!
call.
there is an example under this section: https://github.com/metosin/malli/blob/master/docs/function-schemas.md#instrumentation ("With :gen
we can omit the function body"..)
(defn pow {:malli/schema [:=> [:cat :int] :int] :malli/gen true} [x] (* x x))
(defn pow2 {:malli/schema [:=> [:cat :int] :int] :malli/gen false} [x] (* x x))
(md/start! {:gen malli.generator/generate})
(comment
(pow 45)
; => random int
(pow2 45)
; => 2025
)
@U051V5LLP perfect! just what I needed. didn't put it together to use the same argument to start!
, thanks