mapSaga

fun <A, B> Iterable<A>.mapSaga(transform: (A) -> Saga<B>): Saga<List<B>>

Traverses the Iterable and composes all Saga returned by the applies transform function.

data class Order(val id: UUID, val amount: Long)
suspend fun updateOrder(inc: Long): Order = Order(UUID.randomUUID(), 100L + inc)
suspend fun reverseOrder(uuid: UUID, inc: Long): Unit = println("Decrementing order with $uuid with $inc")

listOf(1, 2, 3).traverseSage { amount ->
saga { updateOrder(amount) }.compensate { order -> reverseOrder(order.uuid, amount) }
}.transact()

Sources

common source
Link copied to clipboard