Nuovo a informe e ho una domanda sull'uso di funzioni polimorfiche che richiedono alcune dipendenze. Io fondamentalmente ho questo codice e voglia di tirare oggetto somePoly fuori del metodo run:Estrarre le funzioni polimorfiche senza forma che hanno dipendenze
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))
}
}
Un modo ho pensato di farlo era come questo, ma sembra disordinato:
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))
}
}
Chiunque ha tutte le consigli?
Discussione relativa gitter https://gitter.im/milessabin/shapeless?at=56608190d2a5a7813cd41422 – cvogt