This ppx adds a construct similar to if let
in Rust.
The following two snippets are equivalent:
let%if Some x = Sys.getenv_opt "HELLO" in
print_endline x
match Sys.getenv_opt "HELLO" with
| Some x -> print_endline x
| _ -> ()
Do you often want to perform side effects if an expression is true while still returning the boolean value?
Then if%true
is for you!
Simply write:
if%true cond then something else otherwise
... and your code is automagically transformed into:
let c = cond in (if c then something else otherwise); c
The else branch is optional!