Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active September 20, 2019 06:19
Show Gist options
  • Save adamw/b73e667506f810af00bd288ce6a03b0f to your computer and use it in GitHub Desktop.
Save adamw/b73e667506f810af00bd288ce6a03b0f to your computer and use it in GitHub Desktop.
// Re-useable effect descriptions
val sendEmail: IO[Unit] = IO(println("Sending email"))
val insertUser: ConnectionIO[Int] =
sql"INSERT INTO users(name, email) VALUES('Emily', '[email protected]')"
.update.run
// (1) BEGIN; INSERT; sendEmail(); COMMIT;
val insertThenSend: ConnectionIO[Unit] =
insertUser.flatMap(_ => sendEmail.to[ConnectionIO])
val result1: IO[Unit] = insertThenSend.transact(transactor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment