This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-31
Channels
- # adventofcode (4)
- # ai (1)
- # announcements (13)
- # babashka (1)
- # beginners (42)
- # calva (15)
- # chlorine-clover (28)
- # cider (7)
- # cljsrn (1)
- # clojure (3)
- # clojure-china (1)
- # clojure-dev (4)
- # clojure-europe (7)
- # clojure-losangeles (1)
- # clojure-nl (3)
- # clojure-nlp (2)
- # clojure-sweden (12)
- # clojure-uk (2)
- # clojurescript (30)
- # code-reviews (36)
- # core-async (5)
- # cursive (10)
- # data-science (1)
- # datalevin (1)
- # fulcro (11)
- # introduce-yourself (1)
- # lsp (10)
- # malli (7)
- # minecraft (24)
- # missionary (10)
- # monads (6)
- # nrepl (4)
- # off-topic (11)
- # portal (4)
- # rdf (1)
- # reagent (3)
- # releases (4)
- # shadow-cljs (4)
- # spacemacs (4)
How does one make a relation between the input and output of a function? For instance, if I had the function (defn dothings [x y] (/ x y)), I want to check that (zero? (mod x :ret)). In spec you can do this with the :fn option in fdef, but I can't find any way to use malli's :fn option this way in a :=> schema
e.g. with map-syntax:
{:type :=>
:input {:type :cat, :children [{:type :int}]}
:output :int}
=>
{:type :=>
:input {:type :cat, :children [{:type :int}]}
:output :int
:fn ...}
not sure where that should be in the vector-syntax. optional third element?In this case, I think it's the way to go. The :=>
satisfies the SchemaAST
so it can read & write them from there. Brilliant!
added some options to destructuring parser:
(defn parse
"Takes a destructuring bindings vector (arglist)
and returns a map with keys:
| key | description |
| ---------------|-------------|
| `:raw-arglist` | the original arglist (can have type-hints)
| `:arglist` | simplified clojure arglist (no type-hints)
| `:schema` | extracted malli schema
| `:parsed` | full parse results
Parsing can be configured using the following options:
| key | description |
| -----------------------|-------------|
| `::md/inline-schemas` | support plumatic-style inline schemas (true)
| `::md/sequential-maps` | support sequential maps in non-rest position (true)
| `::md/required-keys` | are destructured keys required (false)
| `::md/closed-maps` | are destructured maps closed (false)
| `::md/references` | are schema references used (false)
Examples:
(require '[malli.destructure :as md])
(-> '[a b & cs] (md/parse) :schema)
; => [:cat :any :any [:* :any]]
(-> '[a :- :string, b & cs :- [:* :int]] (md/parse) :schema)
; => [:cat :string :any [:* :int]]"
any comments to https://github.com/metosin/malli/pull/606? naming, defaults etc. will ship that… next year 🙂