Last active
November 5, 2015 16:45
-
-
Save purijatin/d8134a7a26874eb5c168 to your computer and use it in GitHub Desktop.
This is damn good
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
//source: http://www.cakesolutions.net/teamblogs/default-type-parameters-with-implicits-in-scala | |
object Prac { | |
trait DefaultsTo[Type, Default] | |
object DefaultsTo { | |
implicit def defaultDefaultsTo[T]: DefaultsTo[T, T] = null | |
implicit def fallback[T, D]: DefaultsTo[T, D] = null | |
} | |
type Def[Default] = { | |
type l[Type] = DefaultsTo[Type, Default] | |
} | |
type Document = String | |
class Storage[DocType: Def[Document]#l](name: String){ | |
def t:DocType = ??? | |
} | |
def main(args: Array[String]) { | |
val settings = new Storage("settings") // inferred as Table[Document] | |
val s:Document = settings.t | |
trait User | |
val users = new Storage[User]("users") // inferred as Table[User] | |
val ss:User = users.t | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment