Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rizo/optimist
Everything is going to be Ok.
https://github.com/rizo/optimist
Last synced: about 1 month ago
JSON representation
Everything is going to be Ok.
- Host: GitHub
- URL: https://github.com/rizo/optimist
- Owner: rizo
- License: mit
- Created: 2024-03-25T17:41:58.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-22T16:44:10.000Z (9 months ago)
- Last Synced: 2024-04-22T18:12:05.427Z (9 months ago)
- Language: OCaml
- Size: 13.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Optimist
An OCaml ppx that helps you write happier code.
## Supported rewrite rules
```ocaml
let%ok ... = ... in ...
let%some ... = ... in ...
let%await ... = ... in ...
let%await.ok ... = ... in ...
let%await.some ... = ... in ...match%ok ... with ...
match%some ... with ...
match%await ... with ...
match%await.ok ... with ...
match%await.some ... with ...if%ok ... then ... else ...
if%some ... then ... else ...
if%await ... then ... else ...
if%await.ok ... then ... else ...
if%await.some ... then ... else ...
```## Lwt backtrace propagation
The main difference between using `(let*)` and `let%await` (or the standard
`let%lwt`) is that, with the ppx version, the async exceptions will correctly
propagate their backtraces.The following example demonstrates the fully expanded code for `%await.ok`
```ocaml
let%await.ok p = m in e(* Is desugared into... *)
let module Reraise = struct
external reraise : exn -> 'a = "%reraise"
end
in
Lwt.backtrace_bind
(fun exn -> try Reraise.reraise exn with exn -> exn)
m
(fun p_result ->
match with
| Ok p -> e
| Error err -> Lwt.return (Error err))
```