Skip to content

Instantly share code, notes, and snippets.

@bergmark
Last active July 13, 2017 07:43
Show Gist options
  • Select an option

  • Save bergmark/de959929c8ad10a7369ba0eafe629417 to your computer and use it in GitHub Desktop.

Select an option

Save bergmark/de959929c8ad10a7369ba0eafe629417 to your computer and use it in GitHub Desktop.
trait AbstractResource[T] {
val version: String
type Foo
implicit def self: this.type = this
}
object MyResource extends AbstractResource[MyResource] {
override final val version = "v3"
override type Foo = Int
}
class MyResource
object Foo {
def printVersion[T]()(implicit resource: AbstractResource[T]): Unit =
println(resource.version)
printVersion[MyResource]()
def printFoo[T](implicit resource: AbstractResource[T]): (resource.Foo) => Unit =
(foo: resource.Foo) => println(foo)
val printInt: (Int) => Unit = printFoo[MyResource]
printInt(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment