Satyam Agarwal
08/05/2020, 2:19 PMIO
like we have in Validated
by using Semigroup with applicative, we can get a list of all the failures.
I see we have IOSemiGroup
which has combine method, but I don’t it will give me the desired effect right ? Because IO
encapsulates Throwable
, so it will be always IO<A>
while Throwable
will be first failure while combining.
I have seen the same thing with parTraverse
on IO
. I got the desired effect by giving myIOOp.attempt()
to parTraverse
. Then I get IO<List<Either<Throwable, A>>>
, so with this I can extract out all failures.
But it becomes complicated quickly.
Validated applicative
is neat, and uses tupledN
which is nice so I don’t have to resort to coverting to List
first.
So, is there a way ?simon.vergauwen
08/05/2020, 2:39 PMparTraverse
for Iterable<A>
.
val List<ValidatedNel<Throwable, A>> = listOf(1, 2, 3).parTraverse { i -> Validated.catch { f(i) } }
And then you can sequence
List<ValidatedNel<Throwable, A>>
to ValidatedNel<Throwable, List<A>>
.
Looking at the implementation of parTraverse
and the impl of List.sequence
you can probably flatten these 2 operations into a single one.simon.vergauwen
08/05/2020, 2:40 PMIO
you can follow the same pattern, but it'll involve a 3rd wrapper IO
instead of suspend
.Satyam Agarwal
08/05/2020, 2:44 PM