https://github.com/reynir/let-if
https://github.com/reynir/let-if
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/reynir/let-if
- Owner: reynir
- Created: 2018-08-03T21:50:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-16T16:26:27.000Z (5 months ago)
- Last Synced: 2025-03-24T07:49:02.353Z (3 months ago)
- Language: OCaml
- Size: 8.79 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
Awesome Lists containing this project
README
# let%if is if let backwards
This ppx adds a construct similar to `if let` in Rust.
The following two snippets are equivalent:```OCaml
let%if Some x = Sys.getenv_opt "HELLO" in
print_endline x
``````OCaml
match Sys.getenv_opt "HELLO" with
| Some x -> print_endline x
| _ -> ()
```# New: if%true then do
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:```OCaml
if%true cond then something else otherwise
```... and your code is automagically transformed into:
```OCaml
let c = cond in (if c then something else otherwise); c
```The else branch is optional!