package yocaml

  1. Overview
  2. Docs
Core engine of the YOCaml Static Site Generator

Install

dune-project
 Dependency

Authors

Maintainers

Sources

yocaml-2.3.0.tbz
sha256=216c47d4d954a1e210437101a46736a09fb2e198baf12657c13ade8f24aab7cb
sha512=3bef1e6e93644f860d5b4e72b392530eb0d5ba0ae2cabe198b85b90b92cfd2ad19ff0416d77d46760bcd63b9561c409ef1ecfb11ccacef8e474e7a231234b623

doc/yocaml/Yocaml/Data/Validation/Syntax/index.html

Module Validation.SyntaxSource

Binding operators are used to link fields together to build a complete validation.

A typical usage is:

  record (fun assoc ->
      let+ field_a = required assoc "fieldA" validator_a
      and+ field_b = optional assoc "fieldB" validator_b
      and+ field_c = required associ "fieldB" validator_c in
      { field_a, field_b, field_c })
Sourceval (let+) : ('a, 'err) Result.t -> ('a -> 'b) -> ('b, 'err) Result.t

let+ x = v in k x is map (fun x -> k x) v.

Sourceval (and+) : 'a validated_record -> 'b validated_record -> ('a * 'b) validated_record

let+ x = v and+ y = w in k x y is map2 (fun x y -> k x y) v w.

Sourceval (let*) : ('a, 'err) Result.t -> ('a -> ('b, 'err) Result.t) -> ('b, 'err) Result.t

let* r = f x in return r tries to produce a result Ok from the expression f x, if the expression returns Error _, the computation chain is interrupted.

Warning: the semantics of let* are significantly different from a succession of let+ ... and+ ... which allow errors to be collected in parallel (independently), whereas let* captures them sequentially. The composition of let* and let+ is tricky and let* should only be used to validate preconditions.