Created
June 19, 2019 14:42
-
-
Save eed3si9n/0570676c8ff153ca170767a491eaaffc to your computer and use it in GitHub Desktop.
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
| scala> :paste | |
| // Entering paste mode (ctrl-D to finish) | |
| import language.implicitConversions | |
| class A; class B; class C | |
| implicit def a2b(a: A) = new B | |
| implicit def b2c(b: B) = new C | |
| // Exiting paste mode, now interpreting. | |
| import language.implicitConversions | |
| defined class A | |
| defined class B | |
| defined class C | |
| a2b: (a: A)B | |
| b2c: (b: B)C | |
| scala> implicit def chain[T1,T2,T3](implicit c1: T1 => T2, c2: T2 => T3): T1 => T3 = { (x: T1) => c2(c1(x)) } | |
| chain: [T1, T2, T3](implicit c1: T1 => T2, implicit c2: T2 => T3)T1 => T3 | |
| scala> implicitly[A => C] | |
| res0: A => C = $$Lambda$3917/534276658@7f7e0dd5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment