par Sequence Either
Deprecated
Prefer composing parMap with either DSL
Replace with
import arrow.fx.coroutines.parMap
import arrow.core.continuations.either
import kotlinx.coroutines.Dispatchers
either<E, List<B>> { this.parMap(Dispatchers.Default) { it().bind() } }Sequences all tasks in parallel on Dispatchers.Default and return the result. If one of the tasks returns Either.Left, then it will short-circuit the operation and cancelling all this running tasks, and returning the first encountered Either.Left.
Cancelling this operation cancels all running tasks.
Deprecated
Prefer composing parMap with either DSL
Replace with
import arrow.fx.coroutines.parMap
import arrow.core.continuations.either
import kotlinx.coroutines.Dispatchers
either<E, List<B>> { this.parMap(Dispatchers.Default) { it().bind() } }Deprecated
Prefer composing parMap with either DSL
Replace with
import arrow.fx.coroutines.parMap
import arrow.core.continuations.either
either<E, List<B>> { this.parMap(ctx) { it().bind() } }Sequences all tasks in parallel on ctx and return the result. If one of the tasks returns Either.Left, then it will short-circuit the operation and cancelling all this running tasks, and returning the first encountered Either.Left.
Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with ctx argument. If the combined context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. WARNING If the combined context has a single threaded ContinuationInterceptor, this function will not run in parallel.
Cancelling this operation cancels all running tasks.
import arrow.core.*
import arrow.fx.coroutines.*
import kotlinx.coroutines.Dispatchers
object Error
typealias Task = suspend () -> Either<Throwable, Unit>
suspend fun main(): Unit {
//sampleStart
fun getTask(id: Int): Task =
suspend { Either.catch { println("Working on task $id on ${Thread.currentThread().name}") } }
val res = listOf(1, 2, 3)
.map(::getTask)
.parSequenceEither(Dispatchers.IO)
//sampleEnd
println(res)
}Deprecated
Prefer composing parMap with either DSL
Replace with
import arrow.fx.coroutines.parMap
import arrow.core.continuations.either
either<E, List<B>> { this.parMap(ctx) { it().bind() } }