In the code below I am trying to create a HList of Lists but I am facing a compile time error on the last line of this code as:
◾could not find implicit value for parameter tupler: shapeless.ops.hlist.Tupler[shapeless.HList] ◾not enough arguments for method tupled: (implicit tupler: shapeless.ops.hlist.Tupler[shapeless.HList])tupler.Out. Unspecified value parameter tupler.
object Problem extends App {
def combinations[T](n: Int, ls: List[T]) = {
import shapeless._
import HList._
def prepareHListR(t: Int, result: HList): HList = t match {
case t if (t == 0) => result
case _ => prepareHListR(t - 1, rotateLeft(t - 1, ls) :: result)
}
prepareHListR(n, HNil)
}
def rotateLeft[A](i: Int, xs: List[A]) = {
val rot = if (i > 0) i else xs.length + i
xs.drop(rot) ++ xs.take(rot)
}
println(combinations(3, List('a, 'b, 'c, 'd, 'e, 'f)))
}
Output:
List('a, 'b, 'c, 'd, 'e, 'f) :: List('b, 'c, 'd, 'e, 'f, 'a) :: List('c, 'd, 'e, 'f, 'a, 'b) :: HNil
What next I need to do is to create a tuple of these lists as below:
(List('a, 'b, 'c, 'd, 'e, 'f), List('b, 'c, 'd, 'e, 'f, 'a), List('c, 'd, 'e, 'f, 'a, 'b))
For which I am trying:
combinations(3, List('a, 'b, 'c, 'd, 'e, 'f)).tupled
This approach however is working fine on REPL:
scala> import shapeless._
import shapeless._
scala> import HList._
import HList._
scala> val hlist = List(1, 2, 3) :: List(4, 5, 6) :: List(7, 8, 9) :: HNil
hlist: shapeless.::[List[Int],shapeless.::[List[Int],shapeless.::[List[Int],shapeless.HNil]]] = List(1, 2, 3) :: List(4, 5, 6) :: List(7, 8, 9) :: HNil
scala> val t =hlist.tupled
t: (List[Int], List[Int], List[Int]) = (List(1, 2, 3),List(4, 5, 6),List(7, 8, 9))
To me this seems like an issue with type parameter but I am not able to understand it due to mine limited knowledge in both Scala and Shapeless.
Any help is much appreciated! TIA.