Shapeless: abstraction over * arity and getting the return type as a tuple of elements of the inner abstract type

abstract class Test[T] {
  type Value
}

// This is wrong with respect to Scala syntax.
def fun(tests: Test[_]*): Tuple(tests(0)#Value, tests(1)#Value) = {
}

      

What I want is an arity abstraction over an arbitrary number of var args where the type is held by the element of the abstract type Value

as shown above. For example, go from any arrangement to Product, go from Product to HList or whatever, and then from that to a tuple.

def test[F, A, L, S, Rc <: Test[_]](f: F)(implicit ftp: FnToProduct.Aux[F, L => S],
  ev: S <:< Seq[Rc#Value]) {

  val sq = ev(ftp(f))

  // now I'd like to build a type to reference the return sequence in a tuple
  // What is the real way to do the below?
  type ReturnTpe = sq.foldLeft(HNil)((l, col) => col#Value :: l).tupled
}

      

+3


source to share





All Articles