package spotlib

  1. Overview
  2. Docs
type ('a, 'error) t = ('a, 'error) result =
  1. | Ok of 'a
  2. | Error of 'error

Monad.T2 with type ('a,'error) t := `Ok of 'a | `Error of 'error, but Infix contains extra operators

include Monad.S2 with type ('a, 'error) t := ('a, 'error) t
val return : 'a -> ('a, 'z) t
val bind : ('a, 'z) t -> ('a -> ('b, 'z) t) -> ('b, 'z) t
include Monad.EX2 with type ('a, 'error) t := ('a, 'error) t
val fmap : ('a -> 'b) -> ('a, 'z) t -> ('b, 'z) t

fmap in Haskell

val liftM : ('a -> 'b) -> ('a, 'z) t -> ('b, 'z) t

Synonym of fmap

val fmap2 : ('a -> 'b -> 'c) -> ('a, 'z) t -> ('b, 'z) t -> ('c, 'z) t

fmap2 in Haskell

val liftM2 : ('a -> 'b -> 'c) -> ('a, 'z) t -> ('b, 'z) t -> ('c, 'z) t

synonym of fmap2 in Haskell

val void : ('a, 'z) t -> (unit, 'z) t
val seq : ('a, 'z) t list -> ('a list, 'z) t

sequence in Haskell. Not tail recursive.

val seq_ : (unit, 'z) t list -> (unit, 'z) t

sequence_ in Haskell. Not tail recursive.

val mapM : ('a -> ('b, 'z) t) -> 'a list -> ('b list, 'z) t

Not tail recursive

val mapM_ : ('a -> (unit, 'z) t) -> 'a list -> (unit, 'z) t

Not tail recursive

val iteri : (int -> 'a -> (unit, 'z) t) -> 'a list -> (unit, 'z) t

Iteration with index starting from 0. Not tail recursive.

val for_ : int -> int -> (int -> (unit, 'z) t) -> (unit, 'z) t

for like iteration. Not tail recursive

val join : (('a, 'z) t, 'z) t -> ('a, 'z) t
module Infix : sig ... end
include module type of struct include Infix end
include Monad.Infix2 with type ('a, 'error) t := ('a, 'error) t
val (>>=) : ('a, 'z) t -> ('a -> ('b, 'z) t) -> ('b, 'z) t

synonym of bind

val (>>|) : ('a, 'z) t -> ('a -> 'b) -> ('b, 'z) t

synonum of fmap, with the flipped arguments

Applicative style binops

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

same as map, <$> in Haskell

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

<*> in Haskell

val (>>=!) : ('a, 'e) t -> ('e -> ('a, 'e2) t) -> ('a, 'e2) t

bindE

val (>>|!) : ('a, 'e) t -> ('e -> 'e2) -> ('a, 'e2) t

mapE

val fail : 'a -> (_, 'a) t
val catch : (fail:('error -> 'exn) -> 'a) -> ('a, 'error) t

catch f runs f ~fail.

If f ~fail returns a value v then catch f returns `Ok v.

If f ~fail calls fail e, then the execution of the f ~fail immediately exists and catch f returns `Error e

Any exception raised in f ~fail is not caught.

val catch_exn : (unit -> 'a) -> ('a, [> `Exn of exn ]) t

catch_exn f runs f ().

If f () returns a value v then catch f returns Ok v.

If an exception exn raised in f (), catch f returns Error (`Exn exn).

exception IsError

The exception used by from_Ok

val from_Ok : ('a, 'error) t -> 'a

Haskell's fromJust. it raises IsError if the argument is Error _

val result : ('a -> 'b) -> ('c -> 'b) -> ('a, 'c) t -> 'b

Haskell's either

val map_error : ('e -> 'f) -> ('a, 'e) t -> ('a, 'f) t
val at_Error : ('err -> 'a) -> ('a, 'err) t -> 'a

at_Error = result id

val to_option : ('a, 'err) t -> 'a option

Conversion to option type

module Stdlib : sig ... end