Scala shapeless-从基HList派生类型构造函数HList的选择器

Scala shapeless-从基HList派生类型构造函数HList的选择器,scala,shapeless,Scala,Shapeless,我有一个国家枚举和一个HList,它是枚举值的子集: import shapeless._ import iops.hlist.{Comapped, Selector} sealed trait Country case object US extends Country case object DE extends Country case object CA extends Country ... val countries = US :: DE :: HNil 我有一个Price类和

我有一个
国家
枚举和一个HList,它是枚举值的子集

import shapeless._
import iops.hlist.{Comapped, Selector}

sealed trait Country
case object US extends Country
case object DE extends Country
case object CA extends Country
...

val countries = US :: DE :: HNil
我有一个
Price
类和
PriceTable
,如下所示:

case class Price[C <: Country](value: Double)

class PricesTable[CountryList <: HList, PriceList <: HList](prices: PriceList)
  (implicit comapped: Comapped.Aux[PriceList, Price, CountryList]) {

def priceFor[C <: Country](implicit selector: Selector[CountryList, C]: Price[C] = 
  prices.select[Price[C]]
} 

val pricesTable = new PricesTable(Price[US.type](20) :: Price[DE.type](25) :: HNil)

case class Price[C如果您想要获得给定国家类型的价格,因为
country
Price
的类型参数,那么:

class PricesTable[PriceList <: HList](prices: PriceList)(implicit lubC: LUBConstraint[PriceList, Price[_]]) {
  def priceFor[C <: Country](implicit selector: Selector[PriceList, Price[C]]): Price[C] =
    prices.select[Price[C]]
}

class PricesTable[PriceList感谢您的快速回复。调用
priceFor
的代码在作用域中没有
选择器[PriceList,Price[C]]
,而只有
选择器[CountryList,C]
。因此需要从另一个中派生一个。