Fork me on GitHub
#malli
<
2021-12-31
>
Swapneil04:12:34

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

ikitommi07:12:08

@ss2961 currently, no. but would be easy to add. Please write an issue out of that.

ikitommi07:12:02

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?

ikitommi08:12:26

In this case, I think it's the way to go. The :=>satisfies the SchemaAST so it can read & write them from there. Brilliant!

ikitommi07:12:53

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

ikitommi07:12:27

any comments to https://github.com/metosin/malli/pull/606? naming, defaults etc. will ship that… next year 🙂