Created
January 31, 2012 06:31
-
-
Save paulp/1709245 to your computer and use it in GitHub Desktop.
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
// 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