Created
July 6, 2018 14:58
-
-
Save trepidacious/348975e79a9ea97b01d053a8b7dd27ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A Transaction can produce an effect and a result using STMOps. This represents | |
* an atomic operation performed using the STMOps, getting/setting data, etc. | |
* Using a wrapper allows for use of different effects, and serialisation. | |
*/ | |
trait Transaction[A] { | |
def apply[F[_]: Monad](implicit stm: STMOps[F]): F[A] | |
def map[B](f: A => B): Transaction[B] = { | |
val t = this | |
new Transaction[B] { | |
override def apply[F[_] : Monad](implicit stm: STMOps[F]): F[B] = t[F].map(f) | |
} | |
} | |
def flatMap[B](f: A => Transaction[B]): Transaction[B] = { | |
val t = this | |
new Transaction[B] { | |
override def apply[F[_] : Monad](implicit stm: STMOps[F]): F[B] = t[F].flatMap(a => f(a)[F]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment