typed.clj.spec
all
macro
(all & args)
(all :binder
(binder
:x (bind-tv)
:y (bind-tv))
:body
(map-of (tv :x) (tv :y)))
A polymorphic type binding variables over a body. Applied with `inst`.
bind-tv
macro
(bind-tv & args)
(bind-tv :name :x
:kind (spec-between))
A template for all the instantiations of a type variable.
If :dotted true, uses :regex to generate the sequence of instantions
of tv.
:name enables self-recursion.
:kind represents the set of possible values to instantiate
the type variable with. By default this is the set of all
specs `s/spec?`.
Defaults:
- :kind (spec-between)
- :name nil
binder
macro
(binder & args)
(binder
:x (bind-tv :kind (spec-between)
:position #{:output})
:y (bind-tv :kind (spec-between)
:position #{:output}))
A binder of type variables. Generates a map of substitutions
for the binder. Conforming a `binder` against a map of
substitutions will ignore extra variables in substitution and
generate any missing instantiations.
Defaults:
- :kind (spec-between)
- :position #{:input :output}
- :name nil
fcase
macro
(fcase & args)
(fcase
#{0 1} (s/fspec :args (s/cat :first (s/? integer?)) :ret integer?)
2 (s/fspec :args (s/cat :first integer? :second boolean?) :ret integer?)
(s/fspec :args (s/cat :first integer? :second boolean? :more (s/* integer?)) :ret integer?))
Checked in order. LHS can be integer or set of integers.
Final case is default.
fold-binders
macro
(fold-binders template tv & opt)
(fold-binders (coll-of (tv :a)) :a
:wrap vec)
Takes a template and type variable name tv.
When tv is instantiated to a sequence of instantiations,
instantiates a vector template's using the instantiations pairwise,
and then returns the result of passing that vector to :wrap.
Defaults:
- :wrap (fn [xs]
(s/cat ~@(mapcat (fn [i x]
[(keyword (str (name tv) i)) x])
(range)
xs)))
inst
macro
(inst poly subst)
(inst poly {:x int? :y boolean?})
Instantiate a polymorphic type (see: `all`) with a substitution.
Conforms subst against the :binder of poly (which may infer missing
bindings in substitution) and returns the :body of poly after applying
conformed subst.
reduced-of
macro
deprecated in 1.0.12
(reduced-of s)
Deprecated: Use `typed.spec.clojure.core/reduced-spec` as a direct replacement.
spec-between
macro
(spec-between & args)
(spec-between :lower lower :upper upper)
Generates and conforms to symbolic specs between specs lower and upper.
tapp
macro
(tapp tfn args-map)
(tapp tfn {:x int? :y boolean?})
Apply a type function (see: `tfn`) with a substitution.
Conforms subst against the :binder of tfn and returns the :body
of tfn after applying conformed subst.
tfn
macro
(tfn & args)
(tfn :binder
(binder
:x (bind-tv)
:y (bind-tv))
:body
(map-of (tv :x) (tv :y)))
A type-function that binds type variables over a body. Applied
with `tapp`.
tv
macro
(tv tv & opt)
(tv :a
:wrap identity)
An uninstantiated type variable. Acts as a placeholder and must be
substituted away before use.
Optionally takes a function that wraps the type variable after instantiation.
Defaults:
- :wrap clojure.core/identity