score:5

Accepted answer

seq(1, 2, 3) has type seq[int], seq("1", "2", "3") has type seq[string]. both seq[int] and seq[string] are subtypes of seq[any]. so list(seq(1, 2, 3), seq("1", "2", "3")) has type list[seq[any]].

if you want types seq[int] and seq[string] to be preserved then you need not a list but hlist

import shapeless.{hlist, hnil}
import shapeless.ops.hlist.liftall

def f[l <: hlist](seq: l)(implicit ev: liftall[({type l[t] = or[t =:= seq[int], t =:= seq[string]]})#l, l]) = {
  println(seq)
}

f(seq(1, 2, 3) :: seq("1", "2", "3") :: hnil)

Related Query

More Query from same tag