diff options
| author | Pierre-Marie Pédrot | 2020-08-27 16:23:44 +0200 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2020-08-27 16:23:44 +0200 |
| commit | 2062f9cd5ce3c17c128186d1e9e2193528941e5c (patch) | |
| tree | edd7cf41caeedae18d60dc5c859e2532884ab80a /clib | |
| parent | 829d7ac10175c41eaf3ce8ad9531abeab713dcba (diff) | |
| parent | bd00733ef04e4c916ab4a00d80e9ee1142bcd410 (diff) | |
Merge PR #12499: Clean future goals
Ack-by: SkySkimmer
Ack-by: ejgallego
Reviewed-by: mattam82
Reviewed-by: ppedrot
Diffstat (limited to 'clib')
| -rw-r--r-- | clib/option.ml | 2 | ||||
| -rw-r--r-- | clib/option.mli | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/clib/option.ml b/clib/option.ml index c335e836c2..d1775ae3ae 100644 --- a/clib/option.ml +++ b/clib/option.ml @@ -55,6 +55,8 @@ 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 +let filter f x = bind x (fun v -> if f v then x else 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 4c5df30179..4672780cab 100644 --- a/clib/option.mli +++ b/clib/option.mli @@ -46,6 +46,9 @@ 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 +(** [filter f x] is [x] if [x] [Some y] and [f y] is true, [None] otherwise *) +val filter : ('a -> bool) -> 'a option -> 'a option + (** [init b x] returns [Some x] if [b] is [true] and [None] otherwise. *) val init : bool -> 'a -> 'a option |
