From d44447d69c28bdd581452f5b733605192b707998 Mon Sep 17 00:00:00 2001 From: asymmetric <101816+asymmetric@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:12:36 +0100 Subject: [PATCH] example/h-sql: document Lwt.bind --- example/h-sql/README.md | 7 +++++-- example/h-sql/sql.eml.ml | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/example/h-sql/README.md b/example/h-sql/README.md index aab16638..9b518989 100644 --- a/example/h-sql/README.md +++ b/example/h-sql/README.md @@ -7,6 +7,10 @@ prepared statements using [Caqti](https://paurkedal.github.io/ocaml-caqti/caqti/Caqti_connect_sig/module-type-S/module-type-CONNECTION/index.html), a library for talking to SQL databases: +> [!TIP] +> The `let%lwt` syntax is syntactic sugar for `Lwt.bind`, so the two forms below are equivalent (a third option would be using `>>=`). +> For more information, see [here](https://ocsigen.org/lwt/latest/api/Lwt#3_Callbacks). + ```ocaml module type DB = Caqti_lwt.CONNECTION module T = Caqti_type @@ -17,8 +21,7 @@ let list_comments = (T.unit ->* T.(tup2 int string)) "SELECT id, text FROM comment" in fun (module Db : DB) -> - let%lwt comments_or_error = Db.collect_list query () in - Caqti_lwt.or_fail comments_or_error + Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail let add_comment = let query = diff --git a/example/h-sql/sql.eml.ml b/example/h-sql/sql.eml.ml index c542c4d8..0ef7ef79 100644 --- a/example/h-sql/sql.eml.ml +++ b/example/h-sql/sql.eml.ml @@ -7,8 +7,7 @@ let list_comments = (T.unit ->* T.(t2 int string)) "SELECT id, text FROM comment" in fun (module Db : DB) -> - let%lwt comments_or_error = Db.collect_list query () in - Caqti_lwt.or_fail comments_or_error + Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail let add_comment = let query =