From 61c9bd4bc14d3479a98c2b53adf1b86fa84f13bf Mon Sep 17 00:00:00 2001 From: Hugo Herbelin Date: Wed, 21 Feb 2018 21:18:49 +0100 Subject: Add function bind in option.ml. --- clib/option.ml | 3 +++ clib/option.mli | 3 +++ 2 files changed, 6 insertions(+) (limited to 'clib') diff --git a/clib/option.ml b/clib/option.ml index 21913e8f7..32fe2fc5f 100644 --- a/clib/option.ml +++ b/clib/option.ml @@ -52,6 +52,9 @@ let get = function (** [make x] returns [Some x]. *) let make x = Some x +(** [bind x f] is [f y] if [x] is [Some y] and [None] otherwise *) +let bind x f = match x with Some y -> f y | None -> None + (** [init b x] returns [Some x] if [b] is [true] and [None] otherwise. *) let init b x = if b then diff --git a/clib/option.mli b/clib/option.mli index 226099352..67b42268a 100644 --- a/clib/option.mli +++ b/clib/option.mli @@ -43,6 +43,9 @@ val get : 'a option -> 'a (** [make x] returns [Some x]. *) val make : 'a -> 'a option +(** [bind x f] is [f y] if [x] is [Some y] and [None] otherwise *) +val bind : 'a option -> ('a -> 'b option) -> 'b option + (** [init b x] returns [Some x] if [b] is [true] and [None] otherwise. *) val init : bool -> 'a -> 'a option -- cgit v1.2.3