Skip to content

Instantly share code, notes, and snippets.

@stew
Created May 13, 2014 13:39
Show Gist options
  • Save stew/296d4f886feabac29692 to your computer and use it in GitHub Desktop.
Save stew/296d4f886feabac29692 to your computer and use it in GitHub Desktop.
import scalaz._
import Scalaz._
object Main extends App {
def foo[A](list: List[Option[Int]]): Int = {
implicit def plus[A] = new ApplicativePlus[({type λ[A]=Int})#λ] {
def empty[A] = 0
def plus[A](a: Int, b: ⇒ Int) = a + b
def point[A](a: ⇒ A) = a.asInstanceOf[Int]
def ap[A, B](fa: => Int)(f: => Int): Int = 0
}
Foldable[List].compose(Foldable[Option]).collapse[({type λ[A]=Int})#λ, Int](list)
}
println(foo[String](List(Option(1), Option(2), Option(3), None, Option(4)))) // 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment