Reputation: 837
I used the following example:
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
Upvotes: 4
Views: 333
Reputation: 1644
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)
Upvotes: 4