Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created February 5, 2011 21:48
Show Gist options
  • Select an option

  • Save debasishg/812823 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/812823 to your computer and use it in GitHub Desktop.
// works for Validation
scala> val a: Validation[String, Int] = 1.success
a: scalaz.Validation[String,Int] = Success(1)
scala> val b: Validation[String, Int] = 2.success
b: scalaz.Validation[String,Int] = Success(2)
scala> val c: Validation[String, Int] = 3.success
c: scalaz.Validation[String,Int] = Success(3)
scala> List(a, b, c)
res6: List[scalaz.Validation[String,Int]] = List(Success(1), Success(2), Success(3))
scala> res6.sequence[({type λ[α]=Validation[String, α]})#λ, Int]
res8: scalaz.Validation[java.lang.String,List[Int]] = Success(List(1, 2, 3))
// doesn't work for Either
scala> val x: Either[String, Int] = 1.right
x: Either[String,Int] = Right(1)
scala> val y: Either[String, Int] = 2.right
y: Either[String,Int] = Right(2)
scala> val z: Either[String, Int] = 3.right
z: Either[String,Int] = Right(3)
scala> List(x, y, z)
res9: List[Either[String,Int]] = List(Right(1), Right(2), Right(3))
scala> res9.sequence[({type λ[α]=Either[String,α]})#λ, Int]
<console>:22: error: could not find implicit value for parameter n: scalaz.Applicative[[α]Either[java.lang.String,α]]
res9.sequence[({type λ[α]=Either[String,α]})#λ, Int]
^
@retronym

retronym commented Feb 5, 2011

Copy link
Copy Markdown

I assume you're using Scalaz 6.0-SNAPSHOT.

Unfortunately you need to import Monad._ -- the implicit search for Applicative[X] doesn't include the companion objects of sub-types of Applicative.

scala> import Monad._
import Monad._

scala> res1.sequence[({type λ[α]=Either[String,α]})#λ, Int] 
res3: Either[java.lang.String,List[Int]] = Right(List(1, 2, 3))

@debasishg

Copy link
Copy Markdown
Author

Yes .. I am using 6.0-SNAPSHOT .. Thanks for the clarification ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment