par Sequence Validated
Deprecated
Prefer using more generic parMapOrAccumulate. Remove the semigroup parameter if using NonEmptyList, or concrete combine function otherwise.
Replace with
import arrow.fx.coroutines.parMapOrAccumulate
import kotlinx.coroutines.Dispatchers
import arrow.core.Validated
with<Semigroup<E>, Validated<E, List<B>>>(semigroup) { this.parMapOrAccumulate(Dispatchers.Default, { a, b -> a.combine(b) }) { it.invoke().bind() }.toValidated() }Sequences all tasks in parallel on Dispatchers.Default and returns the result. If one or more of the tasks returns Validated.Invalid then all the Validated.Invalid results will be combined using semigroup.
Cancelling this operation cancels all running tasks.
Deprecated
Prefer using more generic parMapOrAccumulate. Remove the semigroup parameter if using NonEmptyList, or concrete combine function otherwise.
Replace with
import arrow.fx.coroutines.parMapOrAccumulate
import kotlinx.coroutines.Dispatchers
import arrow.core.Validated
with<Semigroup<E>, Validated<E, List<B>>>(semigroup) { this.parMapOrAccumulate(Dispatchers.Default, { a, b -> a.combine(b) }) { it.invoke().bind() }.toValidated() }Deprecated
Prefer using more generic parMapOrAccumulate. Remove the semigroup parameter if using NonEmptyList, or concrete combine function otherwise.
Replace with
import arrow.fx.coroutines.parMapOrAccumulate
import arrow.core.Validated
with<Semigroup<E>, Validated<E, List<B>>>(semigroup) { this.parMapOrAccumulate(ctx, { a, b -> a.combine(b) }) { it.invoke().bind() }.toValidated() }Sequences all tasks in parallel on ctx and returns the result. If one or more of the tasks returns Validated.Invalid then all the Validated.Invalid results will be combined using semigroup.
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.typeclasses.Semigroup
import arrow.fx.coroutines.*
import kotlinx.coroutines.Dispatchers
typealias Task = suspend () -> ValidatedNel<Throwable, Unit>
suspend fun main(): Unit {
//sampleStart
fun getTask(id: Int): Task =
suspend { Validated.catchNel { println("Working on task $id on ${Thread.currentThread().name}") } }
val res = listOf(1, 2, 3)
.map(::getTask)
.parSequenceValidated(Dispatchers.IO, Semigroup.nonEmptyList())
//sampleEnd
println(res)
}Deprecated
Prefer using more generic parMapOrAccumulate. Remove the semigroup parameter if using NonEmptyList, or concrete combine function otherwise.
Replace with
import arrow.fx.coroutines.parMapOrAccumulate
import arrow.core.Validated
with<Semigroup<E>, Validated<E, List<A>>>(semigroup) { this.parMapOrAccumulate(ctx, { a, b -> a.combine(b) }) { it.invoke().bind() }.toValidated() }