Skip to content

Instantly share code, notes, and snippets.

@mushtaq
Created November 1, 2011 13:21
Show Gist options
  • Save mushtaq/1330483 to your computer and use it in GitHub Desktop.
Save mushtaq/1330483 to your computer and use it in GitHub Desktop.
For patrick
trait Block[T] extends Function1[String, T]
object Block {
implicit def functionBlock[T](f: String => T): Block[T] = new Block[T] {
def apply(s: String): T = f(s)
}
implicit val unitBlock: Block[Unit] = new Block[Unit] {
def apply(s: String): Unit = {}
}
}
object A {
def get[T](uri: String)(implicit block: Block[T]): T = {
println("before...")
val result = block(uri.reverse)
println("after...")
result
}
val result = get("http") {
r: String => println(r); 42
}
val result1 = get("http")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment