simon.vergauwen
12/07/2021, 3:03 PMthanh
12/07/2021, 7:29 PMthanh
12/07/2021, 8:15 PMsimon.vergauwen
12/07/2021, 8:58 PMsimon.vergauwen
12/07/2021, 8:59 PMCont
will also be useful.simon.vergauwen
12/07/2021, 8:59 PMCont<E, A> <~~> suspend () -> Either<E, A>
simon.vergauwen
12/07/2021, 9:07 PMIO
vs Either
. When you receive an Either
value the program has already run, but if you receive a Cont
you can still control where the operation runs.
I.e.
// Exposed
suspend fun <E, A> Cont<E, A>.transaction(db: Database): Either<E, A> =
newSuspendedTransaction(db, <http://Dispatchers.IO|Dispatchers.IO>) {
// run the `suspend () -> E | A` by calling fold
fold({ e -> rollback(); Either.Left(e) }, { a -> Either.Right(a) })
}
simon.vergauwen
12/07/2021, 9:07 PMsimon.vergauwen
12/07/2021, 9:08 PMMonadError
to abstract over things like validation for Either
, Option
, Validated
, ..thanh
12/08/2021, 9:09 AMCont
is a function and it is only evaluated to value by using fold
function and some other similar functions like toEither
.thanh
12/08/2021, 9:11 AMEither
( copy from your gist about Sqldelight Transaction) which works great, but it seems a little bit better with Cont
.simon.vergauwen
12/08/2021, 9:12 AMthanh
12/08/2021, 9:13 AMIvan Dugalic
12/08/2021, 10:06 AMsimon.vergauwen
12/08/2021, 10:49 AM