Created
November 22, 2011 10:10
-
-
Save einblicker/1385350 to your computer and use it in GitHub Desktop.
FastForall
This file contains hidden or 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.Forall | |
object FastForall { | |
type Not[A] = A => Unit | |
type DNE[P[_]] = Not[P[A]] forSome { type A } | |
type CPS[P[_]] = Not[DNE[P]] | |
def apply[P[_]](p: CPS[P]): Forall[P] = new Forall[P] { | |
private var cache: Option[P[_]] = None | |
def apply[A]: P[A] = synchronized { | |
if (cache.isEmpty) p((arg:P[A]) => cache = Some(arg)) | |
cache.get.asInstanceOf[P[A]] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment