package reason-standard

  1. Overview
  2. Docs

In functions that make heavy use of Results placing an

open Result.Infix

Can make code significantly more concise at the expense of placing a greater cognitive burden on future readers.

val (>>=) : ('ok, 'error) Result.t -> ('ok -> ('b, 'error) Result.t) -> ('b, 'error) Result.t

An operator version of flatMap

Examples

The following examples assume

open Result.Infix

let reciprical (x:float) : (string, float) Standard.Result.t =
  if (x = 0.0) then
    Error "Divide by zero"
  else
    Ok (1.0 /. x)

Is in scope.

Ok 4. >>= reciprical = Ok 0.25
Error "Missing number!" >>= reciprical = Error "Missing number!"
Ok 0. >>= reciprical = Error "Divide by zero"
val (>>|) : ('a, 'error) Result.t -> ('a -> 'b) -> ('b, 'error) Result.t

An operator version of map

Examples

The following examples assume open Result.Infix is in scope.

Ok 4 >>| Int.add(1) = Ok 5
Error "Its gone bad" >>| Int.add(1) = Error "Its gone bad"
OCaml

Innovation. Community. Security.