package preface

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Implementation for Try.t.

Validate.t is a biased version of Validation with the errors fixed as an Nonempty_list of exception.

Type

type 'a t = ('a, exn Nonempty_list.t) Validation.t

About Validate

Validate is a specialisation of Validation, so the module does not re-export the Validation constructors (they do not have the same arity) so if you want to pattern match a Validate value you will have to use the Validation constructors:

match validated_value with
| Validation.Valid x -> x
| Validation.Invalid errors ->
  Format.sprintf "Error: %a" (Nonempty_list.pp Exn.pp) errors

Implementation

Functor

module Functor : Preface_specs.FUNCTOR with type 'a t = 'a t

Alt

module Alt : Preface_specs.ALT with type 'a t = 'a t

Applicative

Validate.t implements Preface_specs.APPLICATIVE and introduces an interface to define Preface_specs.TRAVERSABLE using Validate as an iterable structure.

As you can see, it is in the definition of the Preface_specs.APPLICATIVE that Validate differs from Try. The 'errors part must be a Preface_specs.SEMIGROUP to allow for the accumulation of errors.

Selective

module Selective : Preface_specs.SELECTIVE with type 'a t = 'a t

Monad

Validate.t implements Preface_specs.MONAD and introduces an interface to define Preface_specs.TRAVERSABLE using Validate as an iterable structure.

Foldable

module Foldable : Preface_specs.FOLDABLE with type 'a t = 'a t

Addtional functions

Additional functions to facilitate practical work with Validate.t.

val pure : 'a -> 'a t

Create a value from 'a to 'a t.

val valid : 'a -> 'a t

Wrap a value into Valid.

val invalid : exn Nonempty_list.t -> 'a t

Wrap an exception list into Invalid.

val error : exn -> 'a t

Wrap an exception into a list and wrap the list into Invalid.

val case : ('a -> 'b) -> (exn Nonempty_list.t -> 'b) -> 'a t -> 'b

case f g x apply f if x is Valid, g if x is Invalid.

val to_result : 'a t -> ('a, exn Nonempty_list.t) result

Project a Validate into a Result.

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

Equality between Validate.t.

val pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Formatter for pretty-printing for Validate.t.

OCaml

Innovation. Community. Security.