module type S = Async_kernel__.Async_invariant_intf.Async.S
module type S1 = Async_kernel__.Async_invariant_intf.Async.S1
module type S2 = Async_kernel__.Async_invariant_intf.Async.S2
module type S3 = Async_kernel__.Async_invariant_intf.Async.S3
val invariant : Core_kernel.Source_code_position.t ‑> 'a ‑> ('a ‑> Core_kernel.Sexp.t) ‑> (unit ‑> unit Async_kernel.Deferred.t) ‑> unit Async_kernel.Deferred.t
val check_field : 'a ‑> 'b t ‑> unit Async_kernel.Deferred.t ‑> ('a, 'b) Core_kernel.Field.t ‑> unit Async_kernel.Deferred.t
check_field
can be used to check record fields when using [@@deriving fields]
.
Idiomatic usage looks like:
type t = { foo : Foo.t ; bar : Bar.t }
[@@deriving fields]
let invariant t =
Invariant.Async.invariant [%here] t [%sexp_of: t] (fun () ->
let check inv = Invariant.Async.check_field t inv in
Fields.fold ~init:(return ())
~foo: (check Foo.invariant)
~bar: (check Bar.invariant)
When some fields have synchronous invariants, or do not need to be checked, it
may be useful to define a second wrapper around check_field
:
type t = { foo : Foo.t ; bar : Bar.t ; quux : Quux.t }
[@@deriving fields]
let invariant t =
Invariant.Async.invariant [%here] t [%sexp_of: t] (fun () ->
let check' inv = Invariant.Async.check_field t inv in
let check inv = check' (fun x -> inv x; return ()) in
Fields.fold ~init:(return ())
~foo: (check' Foo.invariant)
~bar: (check Bar.invariant)
~quux: (check ignore)