scala - 如何提取缩小类型并将其用于 Shapeless 的副产品?
问题描述
有这个代码:
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 中编译:
推荐阅读
- android - 如何在颤动中从UST获取当地时间
- javascript - 我的 javascript 片段返回“非法字符”
- tm - 如何清理 csv 文件的两列中的数据,其中包含许多行作为文档
- mongodb - 获取“org.springframework.data.mongodb.UncategorizedMongoDbException: 'can't convert from BSON type string to Date'”异常
- google-cloud-platform - 无法将静态 IP 连接到 GKE 上的 Ingress
- c# - 创建后我的 TextBlock 有多宽?
- php - 在索引和值上解释数组和 ++ 运算符
- javascript - 如何专注于 Angular 中的顶部锚标记?
- xml - fn:boolean 它有什么用?
- angular - 如何在 mat-form-field 中获取输入的点击事件?