clojure.core.typed.contract
A contract system a la racket/contract.
Main entry point is the `contract` macro.
and-c
(and-c & cs)
Returns a contract that ensures a value passes each contract `cs`.
At most *one* higher-order contract may be passed to `and-c`, and
any number of flat contracts.
[Contract * -> Contract]
eg. (and-c (instance-c Boolean) true-c) ;; (I Boolean true)
any-c
Contract that allows any value.
contract
macro
(contract c x)
(contract c x b)
Check a contract against a value, with an optional Blame object.
(IFn [Contract Any -> Any]
[Contract Any Blame -> Any])
contract*
(contract* c x b)
Like contract except blame must be provided.
count-range-c
(count-range-c lower)
(count-range-c lower upper)
Returns a flat contract that allows values with `count`
greater-or-equal-to lower, and less-or-equal-to upper.
Upper can be nil for positive infinity.
(IFn [Int -> Contract]
[Int (U nil Int) -> Contract])
eg. (count-range-c 0 10)
(count-range-c 0 nil)
equiv-c
(equiv-c y)
Returns a flat contract that returns true if a value is `=`
to y.
[Any -> Contract]
false-c
Contract that checks for `false`.
flat-val-c
(flat-val-c name pred)
Contract generation for flat predicates.
hmap-c
(hmap-c & {:keys [mandatory optional absent-keys complete?], :or {absent-keys #{}, mandatory {}, optional {}, complete? false}})
Takes a map of mandatory and optional entry contracts,
a set of absent keys, and :complete? true if this is a fully
specified map. Intended to work with keyword keys, but should
work with any keys looked up via =.
identical-c
(identical-c y)
Returns a flat contract that returns true if a value is `identical?`
to y.
[Any -> Contract]
ifn-c
(ifn-c cs c2)
Returns a function contract that checks a function has
fixed domain that passes contracts `cs` and return value
that passes contact `c2`.
[(Vec Contract) Contract -> Contract]
eg. (ifn-c [int-c] int-c) ;; [Int -> Int] contract
instance-c
macro
(instance-c c)
Flat contracts for instance? checks on Class's.
instance-c*
(instance-c* c pred)
int-c
Flat contract for values that pass `integer?`.
make-blame
(make-blame & {:as bls})
Make a new blame object.
Keyword arguments:
- :message A string message, String
- :positive Positive blame party, (U String Symbol)
- :negative Negative blame party, (U String Symbol)
- :file File that contains contract, (U Str nil)
- :line Line where contract occurs, (U Int nil)
- :column Column where contract occurs, (U Int nil)
make-contract
(make-contract & {:keys [name first-order projection flat?], :or {flat? false}})
Make a new contract.
Keyword arguments: (see Contract datatype for more details)
- :name Name of the contract, (U Symbol String)
- :first-order First-order predicate for this contract, [Any -> Any]
- :projection Curried function taking blame and the value to check,
and returns a new checked value, or throws blame.
[Blame -> [Any -> Any]]
- :flat? True if this is a flat contract, Boolean
make-flat-contract
(make-flat-contract & args)
Calls `make-contract` but also passes `:flat? true` as the first arguments.
nil-c
Contract that checks for `nil`.
or-c
(or-c & cs)
Returns a contract that checks a value passes at least
one of the contracts `cs`.
Any number of flat contracts may be passed to or-c. However,
if more than one higher-order contract is provided, each time
this contract is used, at most *one* may pass its first-order
predicate.
For example, (or-c (ifn-c [int-c] int-c) (ifn-c [] int-c))
cannot be checked against `clojure.core/+` because
the first-order check for both contracts (`ifn?`) passes.
[Contract * -> Contract]
eg. (or-c int-c nil-c) ;; (U Int nil)
(or-c int-c (ifn-c [int-c] int-c)) ;; (U Int [Int -> Int])
seqable-c
(seqable-c c)
Alpha - subject to change.
Returns a contract that checks Seqable things.
[Contract -> Contract]
swap-blame
(swap-blame x)
Swap a blame object's blame parties.
[Blame -> Blame]
throw-blame
(throw-blame {:keys [message positive negative file line column], :as b})
Throw a blame object
[Blame -> Nothing]
true-c
Contract that checks for `true`.