Marcin Gryszko
05/29/2020, 6:46 AMConcurrent - I tried in my program replacing Concurrent.parMapN with a ParApplicative instance (obtained by Concurrent.parApplicative(ctx)). Then, I replaced parMapN with mapN and checked which threads effects passed to mapN were executed in. To my surprise, they were executed in the caller's thread:
C.parApplicative(dispatchers().io()).run {
mapN(getAthleteActivities(), getAthlete()) { (apiActivities, apiAthlete) -> /* transform */ }
}
I checked quickly the implementation; to have a concurrent execution, I have to use map2 extension function:
C.parApplicative(dispatchers().io()).run {
getAthleteActivities().map2(getAthlete()) { (apiActivities, apiAthlete) -> /* transform */ }
}
Is this a conscious design decision? Should mapN be delegated to parMapN?simon.vergauwen
05/29/2020, 8:06 AMparMapN.
mapN is derived from product, which delegates to parTupledN.Marcin Gryszko
05/29/2020, 2:57 PMsimon.vergauwen
05/29/2020, 5:26 PMmapN is derived from product, and product does delegate to parMapN in ParApplicative.
https://github.com/arrow-kt/arrow-fx/blob/3ac53b1eaa3ed744e97a13ea201b1e9589237d5b/arrow-fx/src/main/kotlin/arrow/fx/typeclasses/ParApplicative.kt#L27
https://github.com/arrow-kt/arrow-core/blob/master/arrow-core-data/src/main/kotlin/arrow/typeclasses/Apply.kt#L70simon.vergauwen
05/29/2020, 5:26 PMMarcin Gryszko
05/30/2020, 7:15 AM