Transactional Effects in Scala
by
Introduction
This post was inspired by a StackOverflow answer for the question Compose Futures with Recovery in Scala: Is it possible to compose
Futures in a manner where, if one of them fails, a previous
Future's execution result will be rolled back via some function?
The Problem
F[_], so we can say: How can we compose effects
F[_] in a manner where, if one of them fails, the previous
F[_] execution result will be rolled back via some function? This behavior is similar to what we know as a Transaction.
Solution
cats-effect version
Scala
2
3
6
8
9
11
* Here goes syntax trick - in for-comprehension will be invoked `flatMap` of this wrapper and not of underlying effect.