Erik Dreyer
06/22/2022, 8:37 PMflatMap
like operation with two methods that produce ValidatedNel<E,A>
where the “right” side of the first method is an input into the second method?Erik Dreyer
06/22/2022, 8:37 PMErik Dreyer
06/22/2022, 8:37 PMval a: ValidatedNel<E, A> = foo()
val b: ValidatedNel<E, B> = bar(<a's right side>)
// so...
val result: B = a
.map { bar(it) }
.fold(
{ err -> // create a B },
{ result -> // oops, result is a ValidatedNel<E,B>, but I want a B }
)
Erik Dreyer
06/22/2022, 8:58 PMval a: Either<Nel<E>, A> = foo().toEither()
val b: Either<Nel<E>, B> = bar(<a's right side>).toEither()
// like this, basically
val result: Either<Nel<E>, B> = a.flatMap { bar(it).toEither() }
Davis Mohar
06/22/2022, 9:19 PMwithEither{}
function to achieve this. It will convert a Validated to an either within the block, and then automatically convert it back at the endErik Dreyer
06/22/2022, 9:23 PMErik Dreyer
06/22/2022, 9:23 PMraulraja
06/22/2022, 9:24 PMeither
raulraja
06/22/2022, 9:24 PMraulraja
06/22/2022, 9:25 PMbar
depends on the result of foo
the Nel
is not needed since you have no way to invoke bar
without the result of foo
raulraja
06/22/2022, 9:27 PMValidated<String, Int>
without the Nel. Nel
is only useful when you have independent operations and you would like to perform error accumulation.raulraja
06/22/2022, 9:29 PMErik Dreyer
06/22/2022, 9:29 PMfoo()
and bar()
may have multiple errors, so I’ll have to keep the Nel
. Love the use of comprehensions!raulraja
06/22/2022, 9:29 PMraulraja
06/22/2022, 9:31 PMraulraja
06/22/2022, 9:31 PMErik Dreyer
06/22/2022, 9:32 PMeither {}
dsl is deprecated now in favor of effects?raulraja
06/22/2022, 9:33 PMraulraja
06/22/2022, 9:34 PMraulraja
06/22/2022, 9:35 PMraulraja
06/22/2022, 9:35 PMErik Dreyer
06/22/2022, 9:35 PMraulraja
06/22/2022, 9:36 PMErik Dreyer
06/22/2022, 9:36 PMErik Dreyer
06/22/2022, 9:39 PMcontext
come from in
context(EffectScope<String>)
raulraja
06/23/2022, 6:54 AMraulraja
06/23/2022, 6:55 AMTo enable context receivers in your project, use thecompiler option.-Xcontext-receivers
raulraja
06/23/2022, 6:56 AMcontext