ligo/lib_stdlib/option.ml

35 lines
1.0 KiB
OCaml
Raw Normal View History

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. *)
(* *)
(**************************************************************************)
let map ~f = function
| None -> None
| Some x -> Some (f x)
2016-09-08 21:13:10 +04:00
let apply ~f = function
| None -> None
| Some x -> f x
let iter ~f = function
| None -> ()
| Some x -> f x
2016-09-08 21:13:10 +04:00
let unopt ~default = function
| None -> default
| Some x -> x
let unopt_map ~f ~default = function
| None -> default
| Some x -> f x
let first_some a b = match a, b with
| None, None -> None
| None, Some v -> Some v
| Some v, _ -> Some v