package sugar

  1. Overview
  2. Docs

Module Sugar.OptionSource

An implementation of Result interface for the option type.

This is probably the easiest way to start using Sugar, as there is no need to use describe errors. Still, because this module follows the same interface, when you need to start refactoring to more complex, monadic results you get to keep the same clean interface, making be transition straightfoward.

Usage example:

  open Sugar.Option

  let do_something (): string result =
    if true then
      Some "you could use any option type"
    else
      throw ()

  let run (): string result =
    do_something ()
    >----------
    ( fun () ->
      return "recovered"
    )

In case you are wondering, the evaluation of run () in the example above, will produce: string option = Some "you could use any option type".

Sourcetype error = unit
Sourcetype 'a result = 'a option
Sourceval return : 'a -> 'a option
Sourceval throw : unit -> 'a option
Sourceval bind : 'a option -> ('a -> 'b option) -> 'b option
Sourceval bind_unless : 'a option -> (unit -> 'a option) -> 'a option
Sourceval map : 'a option -> ('a -> 'b) -> 'b option
Sourceval (>>=) : 'a option -> ('a -> 'b option) -> 'b option
Sourceval (>>) : unit option -> 'a option -> 'a option
Sourcemodule Infix : sig ... end
Sourceval wrap : (unit -> 'a) -> 'a option
Sourceval unwrap : 'a option -> 'a
Sourceval unwrap_or : 'a option -> (unit -> 'a) -> 'a
Sourceval expect : 'a option -> string -> 'a
Sourcemodule Monad : S.Params.Monad with type 'a t = 'a option