新形狀沒有形狀,我對使用需要某些依賴關係的多態函數有疑問。我基本上有這樣的代碼並想拉somePoly對象了run方法:我認爲這樣做是這樣的拉出具有依賴關係的無形多態函數
import shapeless._
object SomeObject {
type SomeType = Int :+: String :+: (String, Int) :+: CNil
def run(someList: List[SomeType], someInt:Int, someWord:String) = {
object somePoly extends Poly1 {
implicit def doIt = at[Int](i => i + someInt + someWord.length)
implicit def doIt2 = at[String](i => i.length + someWord.length)
implicit def doIt3 = at[(String, Int)](i => i._1.length + someWord.length)
}
someList.map(_.map(somePoly))
}
}
的一種方式,但它似乎凌亂:
object TypeContainer {
type SomeType = Int :+: String :+: (String, Int) :+: CNil
}
case class SomePolyWrapper(someList: List[TypeContainer.SomeType], someInt:Int, someWord:String){
object somePoly extends Poly1 {
implicit def doIt = at[Int](i => i + someInt + someWord.length)
implicit def doIt2 = at[String](i => i.length + someWord.length)
implicit def doIt3 = at[(String, Int)](i => i._1.length + someWord.length)
}
}
object SomeObject {
def run(someList: List[TypeContainer.SomeType], someInt:Int, someWord:String) = {
val somePolyWrapper = SomePolyWrapper(someList, someInt, someWord)
someList.map(_.map(somePolyWrapper.somePoly))
}
}
任何人有任何建議?
相關gitter討論https://gitter.im/milessabin/shapeless?at=56608190d2a5a7813cd41422 – cvogt