4

I used the following example:

https://github.com/milessabin/shapeless/blob/master/examples/src/main/scala/shapeless/examples/flatten.scala

to flatten tuples. However I have now realized that case classes are also flattened. Is their any way I can ensure that only the tuples are flattened?

TIA

user2051561
  • 838
  • 1
  • 7
  • 21

1 Answers1

4

You could require an implicit IsTuple:

object flatten extends LowPriorityFlatten {
  implicit def caseTuple[P <: Product : IsTuple]
      (implicit lfm: Lazy[FlatMapper[P, flatten.type]]) =
    at[P](lfm.value(_))
}

Test:

val v4 = (Bar(Foo("a")), (true, 2.0, "foo"))
val f4 = flatten(v4)
typed[(Bar, Boolean, Double, String)](f4)
devkat
  • 1,624
  • 14
  • 15