Yeni şekilsiz ve bazı bağımlılıklara ihtiyaç duyan polimorfik fonksiyonların kullanımı hakkında bir sorum var. Temelde bu koduna sahip ve çalışma yönteminin dışına somePoly nesneyi çekmek istiyorum: Ben böyleydi yapmayı düşündünüzBağımlılıkları olan şekilsiz polimorfik fonksiyonların dışarı çekilmesi
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))
}
}
Bir şekilde, ancak dağınık görünüyor:
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))
}
}
Herkes herhangi sahip tavsiye?
İlgili gitter tartışması https://gitter.im/milessabin/shapeless?at=56608190d2a5a7813cd41422 – cvogt