Search code examples
scalafunctional-programmingscala-cats

Scala Cats: How do I convert a List[ValidatedNel[E, A]] to Ior[NonEmptyList[E], List[A]]?


I tried:

def convert[E, A](in: List[ValidatedNel[E, A]]): Ior[NonEmptyList[E], List[A]] =
    in.separate

I get:

could not find implicit value for parameter G: cats.Bifoldable[cats.data.ValidatedNel]
[error]     in.separate

I then tried something like this:

  def convert[E, A](in: List[ValidatedNel[E, A]]): Ior[NonEmptyList[E], List[A]] =
    in.traverse(_.toIor)

Now I got:

 could not find implicit value for evidence parameter of type cats.Applicative[G]
[error]     in.traverse(_.toIor)

Solution

  • As @Toxaris mentioned, -Ypartial-unification needed to be toggled on