You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, thanks for the fantastic library and learning resources.
I have Array<Validation<A, B>> and want to aggregate all the successes and failures, e.g. Array<Validation<A, B>> => Validation<Array<A>, Array<B>>.
I thought this was possible using control.monads.sequence, however I seem to get runtime error mr.chain is not a function, so I presume I must be doing something wrong.
I have had success sequencing a list of Eithers, but in my case I want to aggregate the left hand side as well, which from reading this blog post, it appears Validation should help.
Thanks!
The text was updated successfully, but these errors were encountered:
@OliverJAsh Validations implement Applicative, rather than Monad, so sequence (which uses the Monad's interface .chain) doesn't work on them.
There isn't a function to aggregate Validations yet. Validations themselves already aggregate failures when you use .apply(), but the failure needs to have a .concat method. You can write a function to do this as:
constValidation=require('folktale/data/validation');constcurry=require('folktale/core/lambda/curry');constintoArray=(x)=>Array.isArray(x) ? x : [x];constcollect=(validations)=>validations.map(x=>x.failureMap(intoArray)).reduce((a,b)=>a.ap(b),Validation.of(curry(validations.length,(...values)=>values)));
Hi, thanks for the fantastic library and learning resources.
I have
Array<Validation<A, B>>
and want to aggregate all the successes and failures, e.g.Array<Validation<A, B>> => Validation<Array<A>, Array<B>>
.I thought this was possible using
control.monads.sequence
, however I seem to get runtime errormr.chain
is not a function, so I presume I must be doing something wrong.I have had success sequencing a list of
Either
s, but in my case I want to aggregate the left hand side as well, which from reading this blog post, it appearsValidation
should help.Thanks!
The text was updated successfully, but these errors were encountered: