thanh
07/04/2022, 10:21 AMpublic fun <A, B, C> Either<A, B>.combine(SGA: Semigroup<A>, b: Either<A, C>): Either<A, Pair<B, C>>stojan
07/04/2022, 10:35 AMValidated and it's called zip
https://arrow-kt.io/docs/apidocs/arrow-core/arrow.core/zip.html
AFIK it doesn't exist for Eitherthanh
07/04/2022, 10:38 AMValidated and Either is a bit annoying sometime ;(simon.vergauwen
07/04/2022, 11:46 AMEither.
Typically I work with Validated in parts where I am actually validating, and then I simply bind them from either blocks.
For example here,
https://github.com/nomisRev/ktor-arrow-example/blob/e35fbd8e24c253eecf1200b3024caafedf70c908/src/main/kotlin/io/github/nomisrev/validation.kt#L57
https://github.com/nomisRev/ktor-arrow-example/blob/e35fbd8e24c253eecf1200b3024caa[…]0c908/src/main/kotlin/io/github/nomisrev/service/UserService.ktsimon.vergauwen
07/04/2022, 11:47 AMthanh
07/04/2022, 11:52 AMValidated to beginners.simon.vergauwen
07/04/2022, 12:05 PMthanh
07/04/2022, 12:14 PMraulraja
07/04/2022, 12:43 PMsimon.vergauwen
07/04/2022, 12:46 PMzip for Either completely.
Since zip is simply the following, but the snippet below doesn't even suffer from the n-arity issue
either {
transform(a.bind(), b.bind(), c.bind(), ...)
}
That raises another issue though. What about traverse does it accumulate, or not for "Either/Validated".simon.vergauwen
07/04/2022, 12:48 PMthanh
07/04/2022, 1:43 PMtraverse should work as normal, and additional parTraverse for error accumulation.thanh
07/04/2022, 1:44 PMsimon.vergauwen
07/04/2022, 1:49 PMparTraverse from Arrow Fx yessimon.vergauwen
07/04/2022, 1:50 PMparMap / parTraverse naming for error accumulation.simon.vergauwen
07/04/2022, 1:51 PMphldavies
07/05/2022, 8:18 AMsimon.vergauwen
07/05/2022, 8:57 AMmapAccumulate or mapCollect or something along those might be a good API name for such an API. If we can close the gap between Validated and Either we can seriously decrease the API surface 🤔
Is there a use-case for Validated except for traverse w/ Monoid or zip w/ Monoid? cc\\ @Alejandro Serrano MenaAlejandro Serrano Mena
07/05/2022, 10:01 AMzip or `traverse`ing some data structure (maybe not a list, maybe a tree or something like that)Alejandro Serrano Mena
07/05/2022, 10:02 AMValidated<A, B> = Either<NonEmptyList<A>, B> or something like that, and provide specific mapAccumulate which only work when Either has a list insidestojan
07/05/2022, 10:03 AMValidated support any type on the left.... wouldn't that limit the left side to NonEmptyList ?simon.vergauwen
07/05/2022, 11:23 AMstojan
07/05/2022, 11:30 AMValidated and Either are the same. We can convert between both of them without information loss.
The differences are:
• Validated lacks flatMap by design (it used to have andThen which was similar to flatMap)
• Either has a zip that does NOT accumulate errors, Validated.zip accumulates errors
• Validated accumulates errors and Either short circuits on the first error
The short circuit VS error accumulation behaviour right now is based on the container type. If we were to merge both containers we would need some other way to trigger error accumulation VS short circuiting. I'm not sure what that would be and if it would actually make things simpler. 🙂thanh
07/05/2022, 5:28 PMEither for errors accumulation, which can be zipAcccumulate and traverseAccumulate then we don't have to use Validated anymore. At least for my use cases and Simon's examples above.stojan
07/10/2022, 3:17 PMzip method.
For accumulating errors they have Validation which is similar to ValidatedNel and ZValidation which is similar to Validated in ZIO Prelude
https://zio.github.io/zio-prelude/docs/functionaldatatypes/Alejandro Serrano Mena
07/10/2022, 3:59 PMEither and Validated is a common pattern, not only in ZIO, Haskell also follows that trend. But there are also reasons to keep the API simple and have just a single one