[sledge] Add Option.or_else

Summary:
```
val or_else : (unit -> 'a option) -> 'a option -> 'a option
(** [or_else f] is [f ()] on [None] and otherwise identity *)
```

Reviewed By: jvillard

Differential Revision: D20637481

fbshipit-source-id: 72a9d930f
master
Josh Berdine 5 years ago committed by Facebook GitHub Bot
parent 2aacc03880
commit 7fdd3cccbb

@ -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

@ -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

Loading…
Cancel
Save