A little bit of background: There is a .separate
function in cats that allows me to get tuple (F[A], F[B])
out of F[Either[A, B]]
. Given that, one can easily construct Either[F[A], F[B]]
- given we can check F
for emptiness (a monoid would do?). The code for list could look like this
val l: List[Either[_, _]] = ???
l.separate match {
case (Nil, rights) => Right(rights)
case (lefts, _) => Left(lefts)
}
But this seems like a more general concept but I am not quite sure what that is. It looks kinda similar to .sequence
but our G
has two holes. That is, we want a transformation F[G[A, B]] -> G[F[A], F[B]]
.
Do you happen to know if such concept exists or how to achieve this goal with cats without pattern matching / if statements / Either.cond
?