package codept-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file mresult.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
33
34
35
36
37
38
39
40
41
type ('a,'b) t = ('a,'b) result

let is_ok = function Ok _ -> true | Error _ -> false

let all_done undone l =
  if List.for_all is_ok l then
    Ok (List.map (function Ok x -> x | _ -> assert false ) l)
  else
    Error (List.map
              (function Ok d -> undone d
                      | Error h -> h ) l)

let fmap f g = function
  | Error x -> Error (f x)
  | Ok r -> Ok (g r)

module Ok = struct
  let fmap f = function
    | Error _ as h  -> h
    | Ok r -> Ok (f r)
  let (>>|) x f = fmap f x

  let bind f = function
    | Error _ as h  -> h
    | Ok r -> f r
  let (>>=) x f = bind f x
end

module Error = struct
  let fmap f = function
    | Error h  -> Error (f h)
    | Ok _ as r -> r
  let (>>|) x f = fmap f x

  let bind f = function
    | Error h  -> f h
    | Ok _ as r -> r

  let (>>=) x f = bind f x

end