package preface

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

Module Preface_stdlib.ValidationSource

Implementation for Validation.t.

Validation is very similar to Result, the main difference between the two lies in the (delayed) implementation of Preface_specs.APPLICATIVE which allows, unlike Result, the accumulation of errors.

Type

Sourcetype ('a, 'errors) t =
  1. | Valid of 'a
  2. | Invalid of 'errors

Implementation

Bifunctor

module Bifunctor : Preface_specs.BIFUNCTOR with type ('a, 'b) t = ('a, 'b) t

Delayed implementation

By setting the error type of Validation.t it is possible to get implementations for abstractions on constructors of type with an arity of 1.

Functor

Alt

Applicative

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

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

Selective

Monad

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

Foldable

Invariant

Additional functions

Additional functions to facilitate practical work with Validation.t.

Sourceval valid : 'a -> ('a, 'b) t

Wrap a value into Valid.

Sourceval invalid : 'b -> ('a, 'b) t

Wrap an error value Invalid.

Sourceval pure : 'a -> ('a, 'b) t

Alias for valid.

Sourceval case : ('a -> 'c) -> ('b -> 'c) -> ('a, 'b) t -> 'c

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

Sourceval equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a, 'b) t -> ('a, 'b) t -> bool

Equality between Validation.t.

Sourceval pp : (Format.formatter -> 'a -> unit) -> (Format.formatter -> 'b -> unit) -> Format.formatter -> ('a, 'b) t -> unit

Formatter for pretty-printing for Validation.t.

OCaml

Innovation. Community. Security.