Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cats.sequence error while applied on list of either

I want to transform a list of List[Either[String, Int]] en Either[String, List[Int]]. For this, I want to use Cats.sequence :

/* for ammonite users
interp.load.ivy("org.typelevel" %% "cats-core" % "1.0.1")

@
*/

import cats.instances.list._
import cats.instances.either._
import cats.syntax.traverse._

val seqCorrect: List[Either[String, Int]] = List(Right(1), Right(2), Right(3))

val result1 = seqCorrect.sequence

But I have the following error :

Cannot prove that Either[String,Int] <:< G[A].
val result1 = seqCorrect.sequence
                         ^

I found the error message very unhelpful. How do I solve this problem?

like image 396
Moebius Avatar asked Apr 23 '18 10:04

Moebius


1 Answers

I think you may not have enabled partial-unification. The easiest way to do so, is to add the sbt-partial-unification plugin.

If you're on Scala 2.11.9 or newer, you can also simply add the compiler flag:

scalacOptions += "-Ypartial-unification"
like image 180
Luka Jacobowitz Avatar answered Sep 22 '22 12:09

Luka Jacobowitz