如何提取窄类型并将其用于 Shapeless 的副产品?
How do I extract narrowed type and use it in Shapeless's coproduct?
有这个代码:
object Types {
val undefined = "undefined".narrow
type RunnableArgument = BigDecimal :+: String :+: Boolean :+: CNil
}
我想将 undefined
常量的类型作为 RunnableArgument
hlist 元素之一。有可能吗?
在 scala 2.13 中用作 HList 值的单例类型,检查原始 SIP:
https://docs.scala-lang.org/sips/42.type.html
因此,在您的情况下,您可以这样写:
RunnableArgument = "undefined" :+: String :+: Boolean :+: CNil
你也可以使用这个东西作为类型:
type Param = "singleton type"
这在 scastie 中编译:
有这个代码:
object Types {
val undefined = "undefined".narrow
type RunnableArgument = BigDecimal :+: String :+: Boolean :+: CNil
}
我想将 undefined
常量的类型作为 RunnableArgument
hlist 元素之一。有可能吗?
在 scala 2.13 中用作 HList 值的单例类型,检查原始 SIP:
https://docs.scala-lang.org/sips/42.type.html
因此,在您的情况下,您可以这样写:
RunnableArgument = "undefined" :+: String :+: Boolean :+: CNil
你也可以使用这个东西作为类型:
type Param = "singleton type"
这在 scastie 中编译: