package yocaml

  1. Overview
  2. Docs

A specialised version of Result (with Error.t as Error part). Try is very useful for producing sequential validations, where as soon as a step produces an error, the computation sequence is interrupted.

Type

type 'a t = ('a, Error.t) Preface.Result.t

A specialised version of Result.

Constructors

Production of valid (Ok) or invalid (Error) values.

val ok : 'a -> 'a t

Produces a valid value.

val error : Error.t -> 'a t

Produces an invalid value.

Conversions

Produces a Validate from a Try.

val from_validate : ('a, Error.t Preface.Nonempty_list.t) Preface.Validation.t -> 'a t

Produces a Try from a Validate.

Helpers

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

Pretty-printers for Try.t.

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

Equality betweens Try.t.

Implementations

Some implementations of some abstractions offered by Preface.

module Functor : Preface.Specs.FUNCTOR with type 'a t = 'a t

Try is a Functor that (logically) implements map.

Try is an Applicative that (logically) implements apply and pure.

Try is also a Monad that (logically) implements bind and return.

Infix and Syntax operators

module Infix : sig ... end
module Syntax : sig ... end
include module type of Infix with type 'a t := 'a t
include Preface.Specs.Applicative.INFIX with type 'a t := 'a t
include Preface_specs.Apply.INFIX with type 'a t := 'a t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative functor of ('a -> 'b) t over 'a t to 'b t.

val (<**>) : 'a t -> ('a -> 'b) t -> 'b t

Flipped Applicative functor of ('a -> 'b) t over 'a t to 'b t.

val (*>) : unit t -> 'a t -> 'a t

Discard the value of the first argument.

val (<*) : 'a t -> unit t -> 'a t

Discard the value of the second argument.

include Preface.Specs.Monad.INFIX with type 'a t := 'a t
val (=|<) : ('a -> 'b) -> 'a t -> 'b t

Infix version of CORE.map.

val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix flipped version of CORE.map.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Infix flipped version of CORE.bind.

val (=<<) : ('a -> 'b t) -> 'a t -> 'b t

Infix version of CORE.bind.

val (>=>) : ('a -> 'b t) -> ('b -> 'c t) -> 'a -> 'c t

Infix version of CORE.compose_left_to_right.

val (<=<) : ('b -> 'c t) -> ('a -> 'b t) -> 'a -> 'c t

Infix version of OPERATION.compose_right_to_left.

val (>>) : unit t -> 'b t -> 'b t

Sequentially compose two actions, discarding any value produced by the first.

val (<<) : 'a t -> unit t -> 'a t

Sequentially compose two actions, discarding any value produced by the second.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t
val (<&>) : 'a t -> ('a -> 'b) -> 'b t

Flipped and infix version of Preface_specs.Functor.CORE.map.

val (<$) : 'a -> 'b t -> 'a t
val ($>) : 'a t -> 'b -> 'b t

Flipped and infix version of Preface_specs.Functor.OPERATION.replace.

include module type of Syntax with type 'a t := 'a t
include Preface.Specs.Applicative.SYNTAX with type 'a t := 'a t
include Preface_specs.Apply.SYNTAX with type 'a t := 'a t
val and+ : 'a t -> 'b t -> ('a * 'b) t

Product functor mapping from 'a t and 'b t to ('a * 'b) t.

include Preface.Specs.Monad.SYNTAX with type 'a t := 'a t
val let* : 'a t -> ('a -> 'b t) -> 'b t

Syntactic shortcuts for flipped version of CORE.bind:

let* x = e in f is equals to bind (fun x -> f) e.

val let+ : 'a t -> ('a -> 'b) -> 'b t

Syntactic shortcuts for flipped version of CORE.map:

let+ x = e in f is equals to map (fun x -> f) e.