Created
March 23, 2015 16:51
-
-
Save vkostyukov/edd8126165529938dfe3 to your computer and use it in GitHub Desktop.
Fancy implicit views
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
trait %>[From, To] { | |
def apply(x: From): To | |
} | |
def view[From, To](f: From => To): From %> To = | |
new %>[From, To] { | |
def apply(x: From): To = f(x) | |
} | |
implicit i: Int %> String = view(_.toString) | |
def foo[A](a: A)(implicit ev: A %> String): String = ev(a) | |
foo(Some(10)) // does not compile | |
foo(10) // compiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment