2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let map ~f = function
|
|
|
|
| None -> None
|
|
|
|
| Some x -> Some (f x)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let apply ~f = function
|
|
|
|
| None -> None
|
|
|
|
| Some x -> f x
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let iter ~f = function
|
|
|
|
| None -> ()
|
|
|
|
| Some x -> f x
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let unopt ~default = function
|
|
|
|
| None -> default
|
|
|
|
| Some x -> x
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let unopt_map ~f ~default = function
|
|
|
|
| None -> default
|
|
|
|
| Some x -> f x
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-01 02:21:54 +04:00
|
|
|
let unopt_exn err = function
|
|
|
|
| Some x -> x
|
|
|
|
| _ -> raise err
|
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let first_some a b = match a, b with
|
|
|
|
| None, None -> None
|
|
|
|
| None, Some v -> Some v
|
|
|
|
| Some v, _ -> Some v
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-12-15 20:00:50 +04:00
|
|
|
let try_with f =
|
|
|
|
try Some (f ()) with _ -> None
|
2018-01-19 16:54:39 +04:00
|
|
|
|
|
|
|
let some x = Some x
|