Fork me on GitHub

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


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


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)


      (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 naming, defaults etc. will ship that… next year 🙂