package server-reason-react

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

Source file Belt_Result.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
type ('a, 'b) t = ('a, 'b) result = Ok of 'a | Error of 'b

let getExn = function
  | Ok x -> x
  | Error _ ->
      let error = Printf.sprintf "File %s, line %d" __FILE__ __LINE__ in
      Js.Exn.raiseError error

let mapWithDefaultU opt default f =
  match opt with Ok x -> f x | Error _ -> default

let mapWithDefault opt default f = mapWithDefaultU opt default (fun x -> f x)
let mapU opt f = match opt with Ok x -> Ok (f x) | Error y -> Error y
let map opt f = mapU opt (fun x -> f x)
let flatMapU opt f = match opt with Ok x -> f x | Error y -> Error y
let flatMap opt f = flatMapU opt (fun x -> f x)
let getWithDefault opt default = match opt with Ok x -> x | Error _ -> default
let isOk = function Ok _ -> true | Error _ -> false
let isError = function Ok _ -> false | Error _ -> true

let eqU a b f =
  match (a, b) with
  | Ok a, Ok b -> f a b
  | Error _, Ok _ | Ok _, Error _ -> false
  | Error _, Error _ -> true

let eq a b f = eqU a b (fun x y -> f x y)

let cmpU a b f =
  match (a, b) with
  | Ok a, Ok b -> f a b
  | Error _, Ok _ -> -1
  | Ok _, Error _ -> 1
  | Error _, Error _ -> 0

let cmp a b f = cmpU a b (fun x y -> f x y)
OCaml

Innovation. Community. Security.