Module Kxclib.Option

include module type of Stdlib.Option
type !'a t = 'a option =
  1. | None
  2. | Some of 'a
val none : 'a option
val some : 'a -> 'a option
val value : 'a option -> default:'a -> 'a
val join : 'a option option -> 'a option
val map : ('a -> 'b) -> 'a option -> 'b option
val fold : none:'a -> some:('b -> 'a) -> 'b option -> 'a
val iter : ('a -> unit) -> 'a option -> unit
val is_none : 'a option -> bool
val is_some : 'a option -> bool
val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int
val to_result : none:'e -> 'a option -> ('a, 'e) Stdlib.result
val to_list : 'a option -> 'a list
val to_seq : 'a option -> 'a Stdlib.Seq.t
include Monadic with type 'x t := 'x t
val return : 'x -> 'x t
val bind : 'x t -> ('x -> 'y t) -> 'y t
module Ops_monad : MonadOpsS with type 'x t := 'x t
module Ops : sig ... end
val get : 'a t -> 'a
val v : 'a -> 'a t -> 'a
val v' : (unit -> 'a) -> 'a t -> 'a
val or_raise : exn -> 'a t -> 'a
val otherwise : 'a t -> 'a t -> 'a t
val otherwise' : (unit -> 'a t) -> 'a t -> 'a t
val pp : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit
val filter : ('a -> bool) -> 'a t -> 'a t
val fmap : ('a -> 'b t t) -> 'a t -> 'b t
val of_bool : bool -> unit t
val some_if : bool -> 'a -> 'a t
val protect : ?capture:(exn -> bool) -> ('x -> 'y) -> 'x -> 'y option

protect ~capture f x returns Some (f x) except when

  • f x throws an exn s.t. capture exn = true, it returns None
  • f x throws an exn s.t. capture exn = false, it rethrows exn

~capture defaults to fun _exn -> true

val try_make : ?capture:(exn -> bool) -> (unit -> 'x) -> 'x option

try_make ~capture f is protect ~capture f (), thus see protect

~capture defaults to fun _exn -> true

val if_found : (unit -> 'x) -> 'x option

a specialized version of try_make where ~capture is fixed to function Not_found -> true | _ -> false