Created
May 13, 2014 13:39
-
-
Save stew/296d4f886feabac29692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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