drew
04/21/2021, 2:42 PMfun <E, A, B> Validated<E, A>.andThen(next: (A) -> Validated<E, B>): Validated<E, B> =
this.withEither { first ->
first.flatMap { next(it).toEither() }
}
Jannis
04/21/2021, 4:08 PMzip
with it.
In particular this should hold:
validatedA.zip(validatedB, f) ===
validatedA.flatMap { a -> validatedB.map { b -> f(a, b) } }
It is sometimes useful to break this invariant but it usually leads to confusion.
This may not be a huge problem now that we have no more typeclasses (with typeclasses it is very important to follow this rule!).
This function is undeniably useful (so much so that I believe we have Validated.bind()
in the either
effect which is basically the same just for effect blocks). Not sure what the others think about it....drew
04/21/2021, 4:09 PMdrew
04/21/2021, 4:10 PMbind
instanceraulraja
04/21/2021, 4:19 PMdrew
04/21/2021, 4:21 PMnext
arg, right?drew
04/21/2021, 4:21 PMthis
into next
raulraja
04/21/2021, 4:27 PMraulraja
04/21/2021, 4:30 PM