mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
Add CCOpt.return_if
This commit is contained in:
parent
bbda79bbcc
commit
b27acb9bd2
2 changed files with 17 additions and 0 deletions
|
|
@ -218,3 +218,14 @@ let flatten = function
|
|||
flatten (Some None) = None
|
||||
flatten (Some (Some 1)) = Some 1
|
||||
*)
|
||||
|
||||
let return_if b x =
|
||||
if b then
|
||||
Some x
|
||||
else
|
||||
None
|
||||
|
||||
(*$T
|
||||
return_if false 1 = None
|
||||
return_if true 1 = Some 1
|
||||
*)
|
||||
|
|
|
|||
|
|
@ -126,6 +126,12 @@ val flatten : 'a t t -> 'a t
|
|||
(** [flatten] transforms [Some x] into [x].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val return_if : bool -> 'a -> 'a t
|
||||
(** Apply [Some] or [None] depending on a boolean.
|
||||
More precisely, [return_if false x] is [None],
|
||||
and [return_if true x] is [Some x].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
(** {2 Infix Operators}
|
||||
@since 0.16 *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue