Skip to content

Commit

Permalink
Further simplify Empty derivation (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
bplommer authored Jun 2, 2021
1 parent 851c322 commit d4419da
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions core/src/main/scala-3/cats/derived/empty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ trait DerivedEmpty[A] extends Empty[A]:
object DerivedEmpty:
inline given [A]: DerivedEmpty[A] = summonFrom {
case given Empty[A] => delegated
case given K0.Generic[A] => derived
case given K0.ProductInstances[DerivedEmpty, A] => product
case given K0.CoproductGeneric[A] => coproduct
}

def delegated[A](using A: => Empty[A]): DerivedEmpty[A] =
() => A.empty

inline def derived[A](using gen: K0.Generic[A]): DerivedEmpty[A] =
inline gen match
case given K0.ProductGeneric[A] => DerivedEmpty.product
case given K0.CoproductGeneric[A] => DerivedEmpty.coproduct

def product[A](using inst: K0.ProductInstances[DerivedEmpty, A]): DerivedEmpty[A] =
() => inst.construct([A] => (A: DerivedEmpty[A]) => A.empty)

Expand Down

0 comments on commit d4419da

Please sign in to comment.