Mới đến không có hình dạng và tôi có câu hỏi về việc sử dụng các hàm đa hình cần một số phụ thuộc. Tôi về cơ bản có mã này và muốn kéo đối tượng somePoly ra khỏi phương pháp chạy:Kéo các chức năng đa hình không có phụ kiện có các phụ thuộc
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))
}
}
Một cách tôi nghĩ làm việc đó là như thế này, nhưng có vẻ như lộn xộn:
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))
}
}
Bất cứ ai có bất cứ khuyên bảo?
Thảo luận gitter liên quan https://gitter.im/milessabin/shapeless?at=56608190d2a5a7813cd41422 – cvogt