Created
February 3, 2021 06:00
-
-
Save Swoorup/5795be94b8998d3ddd51bce51b92413e to your computer and use it in GitHub Desktop.
Scala 3 Match types Channel subscription
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
case class TradeEvent() | |
case class OrderEvent() | |
type Channel = "trades" | "orders" | |
// def sub2[Channels <: Tuple](channels: Channels)(using Channel <:< Tuple.Union[Channels]) = channels.toList | |
type SelChannel[C <: Tuple] = C match { | |
case "trades" *: xs => TradeEvent | SelChannel[xs] | |
case "orders" *: xs => OrderEvent | SelChannel[xs] | |
case _ => Nothing | |
} | |
def subscribe[Channels <: Tuple](channels: Channels) | |
(using Channel <:< Tuple.Union[Channels]): List[SelChannel[Channels]] = | |
??? | |
val tradeSubscription: List[TradeEvent] = subscribe(Tuple1("trades")) | |
val orderSubscription: List[OrderEvent] = subscribe(Tuple1("orders")) | |
val allSubscription: List[TradeEvent | OrderEvent] = subscribe(("orders", "trades")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment