Skip to content

Instantly share code, notes, and snippets.

@rubenfiszel
Created December 19, 2016 18:22
Show Gist options
  • Save rubenfiszel/8c0adcab0945bf2d6966bc21339f44f0 to your computer and use it in GitHub Desktop.
Save rubenfiszel/8c0adcab0945bf2d6966bc21339f44f0 to your computer and use it in GitHub Desktop.
case class Lambda[A:Rep, B:Rep](f: A => B) extends (A => B) {
val rA = rep[A]
val rB = rep[B]
type InternalB = rB.Internal
lazy val lambda: Exp[rA.Internal => InternalB] = doLambdaDef(f)(rA, rB)
def apply(arg:A):B = {
implicit val mf = rB.m
val apply = Apply(lambda, rA.to(arg))
rB.from(apply)
}
}
def sumIf(x: Lambda[T,Boolean] { type InternalB = scala.Boolean }): Int = {
val lambda: Exp[x.rA.Internal => scala.Boolean] = x.lambda
int(indexedSeq_sumIf(lambda))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment