File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ case class Foo (a : String )
2
+
3
+ trait Arbitrary [T ]
4
+ trait Gen [+ T ]
5
+
6
+ object ArbitraryDerivation :
7
+ given deriveArb [A ](using gen : DerivedGen [A ]): Arbitrary [A ] = ???
8
+
9
+ opaque type DerivedGen [A ] = Gen [A ]
10
+ object DerivedGen extends DerivedGenInstances
11
+
12
+ sealed abstract class DerivedGenInstances :
13
+ inline given derived [A ](using gen : K0 .Generic [A ]): DerivedGen [A ] =
14
+ val dummy : DerivedGen [A ] = ???
15
+ gen.derive(dummy, dummy)
16
+
17
+ // from shapeless3-deriving
18
+ import scala .deriving .*
19
+ object K0 {
20
+ type Kind [C , O ] = C { type Kind = K0 .type ; type MirroredType = O ; type MirroredElemTypes <: Tuple }
21
+ type Generic [O ] = Kind [Mirror , O ]
22
+ type ProductGeneric [O ] = Kind [Mirror .Product , O ]
23
+ type CoproductGeneric [O ] = Kind [Mirror .Sum , O ]
24
+
25
+ extension [F [_], T ](gen : Generic [T ])
26
+ inline def derive (f : => (ProductGeneric [T ] & gen.type ) ?=> F [T ], g : => (CoproductGeneric [T ] & gen.type ) ?=> F [T ]): F [T ] =
27
+ inline gen match {
28
+ case p : ProductGeneric [T ] => f(using p.asInstanceOf )
29
+ case c : CoproductGeneric [T ] => g(using c.asInstanceOf )
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ class Test :
2
+ import ArbitraryDerivation .given
3
+ private def test [A : Arbitrary ]: Unit = {}
4
+ test[Foo ]
You can’t perform that action at this time.
0 commit comments