Skip to content

Instantly share code, notes, and snippets.

@einblicker
Created November 22, 2011 10:10
Show Gist options
  • Save einblicker/1385350 to your computer and use it in GitHub Desktop.
Save einblicker/1385350 to your computer and use it in GitHub Desktop.
FastForall
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