package fmlib

  1. Overview
  2. Docs

Source file option.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
type 'a t = 'a option

let return (a: 'a): 'a t =
    Some a

let fail: 'a t =
    None


let (let* ) (m: 'a t) (f: 'a -> 'b t): 'b t =
    match m with
    | Some a ->
        f a
    | None ->
        None


let (>>=) = (let* )


let map (f: 'a -> 'b) (m: 'a t): 'b t =
    let* a = m in
    return (f a)



let to_list (m: 'a t): 'a list =
    match m with
    | Some a ->
        [a]
    | None ->
        []
OCaml

Innovation. Community. Security.