From c063a91c7c53bd2f29bd05603bfa920744890f41 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Wed, 2 Dec 2020 13:46:46 -0800 Subject: [PATCH] [sledge] Add Option.flat_map Reviewed By: jvillard Differential Revision: D25146161 fbshipit-source-id: a8d60de12 --- sledge/nonstdlib/option.ml | 1 + sledge/nonstdlib/option.mli | 1 + 2 files changed, 2 insertions(+) diff --git a/sledge/nonstdlib/option.ml b/sledge/nonstdlib/option.ml index dce244872..60c96364b 100644 --- a/sledge/nonstdlib/option.ml +++ b/sledge/nonstdlib/option.ml @@ -16,6 +16,7 @@ let pp fmt pp_elt fs = function | None -> () let map_or xo ~default ~f = map_or ~default f xo +let flat_map xo ~f = flat_map f xo let iter xo ~f = iter f xo let exists xo ~f = exists f xo let for_all xo ~f = for_all f xo diff --git a/sledge/nonstdlib/option.mli b/sledge/nonstdlib/option.mli index 8c12075bc..e4d08d032 100644 --- a/sledge/nonstdlib/option.mli +++ b/sledge/nonstdlib/option.mli @@ -17,6 +17,7 @@ include Monad_intf.S with type 'a t := 'a t val pp : ('a_pp -> 'a -> unit, unit) fmt -> 'a_pp -> 'a option pp val map_or : 'a t -> default:'b -> f:('a -> 'b) -> 'b +val flat_map : 'a t -> f:('a -> 'b t) -> 'b t val iter : 'a t -> f:('a -> unit) -> unit val exists : 'a t -> f:('a -> bool) -> bool val for_all : 'a t -> f:('a -> bool) -> bool