Last active
December 19, 2016 10:10
-
-
Save b-studios/2db5a3370810e36d8cac973dbdf7d037 to your computer and use it in GitHub Desktop.
Autoprojection
This file contains 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
// Finds a R in an T | |
trait Select[T, R] { | |
def apply(t: T): R | |
} | |
trait LowPrio { | |
implicit def autoLeft[T, R, O]: Select[(R, O), R] = ??? | |
} | |
object Select extends LowPrio { | |
implicit def autoRight[T, R, O]: Select[(O, R), R] = ??? | |
} | |
def select[T, R](t: T)(implicit sel: Select[T, R]): R = sel(t) | |
val x = (12, "hello") | |
val y: Int = select(x) | |
val z: String = select(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment