schema.instrument
Jump to function (12) ›
- schema.instrument/clear-instrumented!
- schema.instrument/function-schema?
- schema.instrument/instrument!
- schema.instrument/instrumented-original
- schema.instrument/instrumented?
- schema.instrument/schema-check?
- schema.instrument/schema?
- schema.instrument/set-schema-check!
- schema.instrument/unstrument!
- schema.instrument/with-schema-check
- schema.instrument/wrap-with-function-schema
- schema.instrument/wrap-with-schema
schema.instrument/clear-instrumented!#
(clear-instrumented!)
Removes every instrumentation entry. Returns nil.
schema.instrument/function-schema?#
(function-schema? schema)
Returns true if schema is a function schema of the shape
[:=> args-schema return-schema].
Example:
(function-schema? [:=> [:int] :int])
schema.instrument/instrument!#
(instrument! name f schema)
Registers f under name (any key) wrapped with schema. Returns
the wrapped fn. Subsequent calls to unstrument! with the same name
can restore the original via (instrumented-original name).
Example:
(def add* (instrument! :add add [:=> [:int :int] :int]))
schema.instrument/instrumented-original#
(instrumented-original name)
Returns the original, unwrapped function associated with name, or
nil if no instrumentation is registered under name.
Example:
(instrumented-original :add)
schema.instrument/instrumented?#
(instrumented? name)
Returns true if name currently has an instrumentation entry.
Example:
(instrumented? :add)
schema.instrument/schema-check?#
(schema-check?)
Returns true when runtime validation is enabled.
schema.instrument/schema?#
(schema? x)
Returns true if x has the shape of a schema value (a keyword or a
vector whose head is a keyword, including the :=> function marker).
Example:
(schema? :int) ; => true
schema.instrument/set-schema-check!#
(set-schema-check! enabled?)
Enables (true) or disables (false) runtime validation performed by
wrap-with-schema/instrument!. Returns the new value.
schema.instrument/unstrument!#
(unstrument! name)
Unregisters the instrumentation bound to name and returns the
original (unwrapped) function if present, otherwise nil.
Example:
(unstrument! :add)
schema.instrument/with-schema-check#
(with-schema-check enabled? f)
Runs thunk f with runtime validation set to enabled?, restoring
the previous value even if f throws.
schema.instrument/wrap-with-function-schema#
(wrap-with-function-schema f schema)
Convenience: accepts a [:=> args-schema return-schema] schema vector
and returns f wrapped accordingly.
Example:
(wrap-with-function-schema add [:=> [:int :int] :int])
schema.instrument/wrap-with-schema#
(wrap-with-schema f arg-schema return-schema)
Wraps f so each call validates its arguments against arg-schema
(a vector of per-arg schemas) and its return value against
return-schema. When schema-check? returns false at call time
the wrapper short-circuits and invokes f directly, skipping
validation on both sides.
Example:
(wrap-with-schema add [:int :int] :int)