raulraja
06/10/2021, 10:24 AMthanh
06/12/2021, 11:01 AMlistOf(Either.Right("test-1"), Either.Right("test-2"), Either.Right("test-3"))
instead of listOf(Either.Right("test-1"), Either.Left("test-2"), Either.Right("test-3"))
Pedro Sena
06/15/2021, 12:11 PMjavax.transaction
implementation so we could mark methods with @Transactional
but having Either
return types ? (not sure if I make myself clear)simon.vergauwen
06/17/2021, 10:26 AM@Transactional
.simon.vergauwen
06/17/2021, 10:41 AMleonhardt
08/23/2023, 7:49 PMtransactionEither
example to recent versions of Arrow and SQLDelight but thought I'd ask, do you already have an updated example? Or has this idea ever made its way into a library?simon.vergauwen
08/28/2023, 7:38 AMsimon.vergauwen
08/28/2023, 7:45 AMeither { }
is on the outside it will rollback on Left
, and exceptions, when it's on the inside it will never rollback on Left
but only on exceptions.
either {
transactionWithResult {
}
}
leonhardt
08/29/2023, 12:19 AMeither { }
on the outside of transactionWithResult { }
as you suggested! Thank you. However we missed the simplicity of the implied right/left typing in the either
DSL – working within the transactionWithResult
DSL we need to provide "rolled back" results wrapped in a Left and successful results wrapped in a Right. So we made another extension function for our project that makes the types as simple as the either
DSL but automatically rolls back the transaction if any error is raised.
import app.cash.sqldelight.Transacter
import arrow.core.Either
import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.either
fun <Error, A> Transacter.transactionEither(block: Raise<Error>.() -> A): Either<Error, A> {
return transactionWithResult { either { block() }.onLeft { error -> rollback(error.left()) } }
}
It's making it easier to establish a convention in our codebase. I thought I'd share as an example for the search results and in case anyone has an even better way to share.