Last active
July 2, 2023 20:51
-
-
Save deanwampler/db0f956b096e10c753b76548fc7bd2d3 to your computer and use it in GitHub Desktop.
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
val f123a: (T1 | T2 | T3) => String = _ match | |
case t1: T1 => "T1" | |
case t2: T2 => "T2" | |
case t3: T3 => "T3" | |
val f123b: (T1 => String) & (T2 => String) & (T3 => String) = f123a | |
val t123s: Seq[T1 | T2 | T3] = Seq(new T1 {}, new T2 {}, new T3 {}) | |
t123s.map(f123a) | |
t123s.map(f123b) | |
// Note that we can pass f123a or f123b for a function T1 => String. It works similarly for T2 and T3. | |
def stringizeT1(t1: T1)(f: T1 => String): String = f(t1) | |
stringizeT1(new T1 {})(f123a) | |
stringizeT1(new T1 {})(f123b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment