diff --git a/sledge/lib/import/option.ml b/sledge/lib/import/option.ml index b58e5d40b..4aeb58bc9 100644 --- a/sledge/lib/import/option.ml +++ b/sledge/lib/import/option.ml @@ -12,6 +12,7 @@ let pp fmt pp_elt fs = function | Some x -> Format.fprintf fs fmt pp_elt x | None -> () +let or_else ~f = function None -> f () | o -> o let cons xo xs = match xo with Some x -> x :: xs | None -> xs module Monad_syntax = struct diff --git a/sledge/lib/import/option.mli b/sledge/lib/import/option.mli index 0730f4df7..370bebba0 100644 --- a/sledge/lib/import/option.mli +++ b/sledge/lib/import/option.mli @@ -11,6 +11,9 @@ include module type of Core.Option val pp : ('a_pp -> 'a -> unit, unit) fmt -> 'a_pp -> 'a option pp (** Pretty-print an option. *) +val or_else : f:(unit -> 'a option) -> 'a option -> 'a option +(** [or_else ~f] is [f ()] on [None] and otherwise identity *) + val cons : 'a t -> 'a list -> 'a list module Monad_syntax : Monad_syntax with type 'a t := 'a option