Skip to content

Instantly share code, notes, and snippets.

@paulp
Created January 31, 2012 06:31
Show Gist options
  • Save paulp/1709245 to your computer and use it in GitHub Desktop.
Save paulp/1709245 to your computer and use it in GitHub Desktop.
// a little one-time boilerplate
def clazz[T](implicit manifest: M[T]) = manifest.erasure.asInstanceOf[Class[_ <: T]]
def methodType[F: M] : MethodType = {
val classes = manifest[F].typeArguments map (_.erasure)
MethodType.methodType(classes.last, classes.init.toArray[Class[_]])
}
def from[F](implicit m: Manifest[F]): Binder = {
val classes = manifest[F].typeArguments map (_.erasure)
Binder.from(classes.last, classes.init.toArray).cast(methodType[F])
}
// fun with syntax
def testType() {
var binder = from[(String, String) => Int]
assertEquals(methodType[(String, String) => Int], binder.`type`)
binder = binder drop 1
assertEquals(methodType[String => Int], binder.`type`)
}
def testInvoke() {
val target = SBinderTest.concatHandle()
val handle = from[(String, String) => String] invoke target
assertEquals(methodType[(String, String) => String], handle.`type`)
assertEquals("Hello, world", handle.invokeWithArguments("Hello, ", "world"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment