package travesty

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

Or-error monad extensions.

This module contains various extensions for Core's Or_error monad, including monadic traversal over successful values and T_monad extensions.

This module re-exports all of the original monad.

include module type of Core_kernel.Or_error
val bin_t : 'a Bin_prot.Type_class.t -> 'a t Bin_prot.Type_class.t
val bin_read_t : 'a Bin_prot.Read.reader -> 'a t Bin_prot.Read.reader
val __bin_read_t__ : 'a Bin_prot.Read.reader -> (Base.Int.t -> 'a t) Bin_prot.Read.reader
val bin_reader_t : 'a Bin_prot.Type_class.reader -> 'a t Bin_prot.Type_class.reader
val bin_size_t : 'a Bin_prot.Size.sizer -> 'a t Bin_prot.Size.sizer
val bin_write_t : 'a Bin_prot.Write.writer -> 'a t Bin_prot.Write.writer
val bin_writer_t : 'a Bin_prot.Type_class.writer -> 'a t Bin_prot.Type_class.writer
val bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.t
include module type of struct include Base.Or_error end with type 'a t := 'a t
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val hash_fold_t : (Base__.Ppx_hash_lib.Std.Hash.state -> 'a -> Base__.Ppx_hash_lib.Std.Hash.state) -> Base__.Ppx_hash_lib.Std.Hash.state -> 'a t -> Base__.Ppx_hash_lib.Std.Hash.state
val t_of_sexp : (Base__.Ppx_sexp_conv_lib.Sexp.t -> 'a) -> Base__.Ppx_sexp_conv_lib.Sexp.t -> 'a t
val sexp_of_t : ('a -> Base__.Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Base__.Ppx_sexp_conv_lib.Sexp.t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
val map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
val both : 'a t -> 'b t -> ('a * 'b) t
module Applicative_infix = Core_kernel.Or_error.Applicative_infix
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<*) : 'a t -> unit t -> 'a t
val (*>) : unit t -> 'a t -> 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
val bind : 'a t -> f:('a -> 'b t) -> 'b t
val return : 'a -> 'a t
val join : 'a t t -> 'a t
val ignore_m : 'a t -> unit t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
val all_ignore : unit t list -> unit t
  • deprecated [since 2018-02] Use [all_unit]
val is_ok : 'a t -> bool
val is_error : 'a t -> bool
val ignore : 'a t -> unit t
val try_with : ?backtrace:bool -> (unit -> 'a) -> 'a t
val try_with_join : ?backtrace:bool -> (unit -> 'a t) -> 'a t
val ok : 'ok t -> 'ok option
val ok_exn : 'a t -> 'a
val of_exn : ?backtrace:[ `Get | `This of string ] -> exn -> 'a t
val of_exn_result : ('a, exn) Base__.Result.t -> 'a t
val error : ?strict:unit -> string -> 'a -> ('a -> Base__.Sexp.t) -> 'b t
val error_s : Base__.Sexp.t -> 'a t
val error_string : string -> 'a t
val errorf : ('a, unit, string, 'b t) Stdlib.format4 -> 'a
val tag : 'a t -> tag:string -> 'a t
val tag_arg : 'a t -> string -> 'b -> ('b -> Base__.Sexp.t) -> 'a t
val unimplemented : string -> 'a t
val map : 'a t -> f:('a -> 'b) -> 'b t
val iter : 'a t -> f:('a -> unit) -> unit
val iter_error : 'a t -> f:(Base__.Error.t -> unit) -> unit
val combine_errors : 'a t list -> 'a list t
val combine_errors_unit : unit t list -> unit t
val filter_ok_at_least_one : 'a t list -> 'a list t
val find_ok : 'a t list -> 'a t
val find_map_ok : 'a list -> f:('a -> 'b t) -> 'b t
module On_ok : Traversable.S1_container with type 'a t := 'a t

On_ok treats an Or_error value as a traversable container, containing one value when it is Ok and none otherwise.

Monad extensions for Or_error.

include T_monad.Extensions with type 'a t := 'a t
val when_m : Base.bool -> f:(Base.unit -> Base.unit t) -> Base.unit t

when_m predicate ~f returns f () when predicate is true, and return () otherwise.

val unless_m : Base.bool -> f:(Base.unit -> Base.unit t) -> Base.unit t

unless_m predicate ~f returns f () when predicate is false, and return () otherwise.

val tee_m : 'a -> f:('a -> Base.unit t) -> 'a t

tee_m val ~f executes f val for its monadic action, then returns val.

Example:

let fail_if_negative x =
  T_on_error.when_m (Int.is_negative x)
    ~f:(fun () -> Or_error.error_string "value is negative!")
in
Or_error.(
  42 |> T_on_error.tee_m ~f:fail_if_negative >>| (fun x -> x * x)
) (* Ok (1764) *)
OCaml

Innovation. Community. Security.