Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semiauto and auto imports #353

Merged
merged 8 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions core/src/main/scala-3/cats/derived/all.scala

This file was deleted.

2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/commutativeMonoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.kernel.CommutativeMonoid
import shapeless3.deriving.K0

object commutativeMonoid extends CommutativeMonoidDerivation

trait ProductCommutativeMonoid[T[x] <: CommutativeMonoid[x], A](using inst: K0.ProductInstances[T, A])
extends ProductCommutativeSemigroup[T, A], ProductMonoid[T, A], CommutativeMonoid[A] {}

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/commutativeSemigroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.kernel.CommutativeSemigroup
import shapeless3.deriving.{K0, Continue}

object commutativeSemigroup extends CommutativeSemigroupDerivation

trait ProductCommutativeSemigroup[T[x] <: CommutativeSemigroup[x], A](using inst: K0.ProductInstances[T, A])
extends ProductSemigroup[T, A], CommutativeSemigroup[A] {}

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/contravariant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Contravariant
import shapeless3.deriving.K1

object contravariant extends ContravariantDerivation, Instances

trait GenericContravariant[T[x[_]] <: Contravariant[x], F[_]](using inst: K1.Instances[T, F])
extends Contravariant[F]:

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/empty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import alleycats.Empty
import shapeless3.deriving.K0
import scala.compiletime.*

object empty extends EmptyDerivation

type DerivedEmpty[A] = Derived[Empty[A]]
object DerivedEmpty:
type Or[A] = Derived.Or[Empty[A]]
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/scala-3/cats/derived/emptyk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import alleycats.{Empty, EmptyK}
import shapeless3.deriving.{Const, K1}

object emptyk extends EmptyKDerivation

trait ProductEmptyK[T[x[_]] <: EmptyK[x], F[_]](
using inst: K1.ProductInstances[T, F]
) extends EmptyK[F]:
Expand All @@ -14,6 +12,3 @@ trait EmptyKDerivation:
extension (E: EmptyK.type)
inline def derived[F[_]](using gen: K1.ProductGeneric[F]): EmptyK[F] =
new ProductEmptyK[EmptyK, F]{}

given [X](using X: Empty[X]): EmptyK[Const[X]] with
def empty[A]: X = X.empty
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Eq
import shapeless3.deriving.{K0, Complete}

object eq extends EqDerivation

trait ProductEq[T[x] <: Eq[x], A](using inst: K0.ProductInstances[T, A]) extends Eq[A]:

def eqv(x: A, y: A): Boolean =
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import cats.{Eval, Foldable}
import shapeless3.deriving.{Const, Continue, K1}
import scala.compiletime.*

object foldable extends FoldableDerivation, Instances

type DerivedFoldable[F[_]] = Derived[Foldable[F]]
object DerivedFoldable:
type Or[F[_]] = Derived.Or[Foldable[F]]
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/functor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import cats.Functor
import shapeless3.deriving.{Const, K1}
import scala.compiletime.*

object functor extends FunctorDerivation, Instances

type DerivedFunctor[F[_]] = Derived[Functor[F]]
object DerivedFunctor:
type Or[F[_]] = Derived.Or[Functor[F]]
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/hash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import shapeless3.deriving.{K0, Continue}
import scala.compiletime.summonInline
import scala.util.hashing.MurmurHash3

object hash extends HashDerivation

trait ProductHash[T[x] <: Hash[x], A](using inst: K0.ProductInstances[T, A], ev: A <:< Product)
extends ProductEq[T, A], Hash[A]:

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala-3/cats/derived/instances.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats.derived

import cats.*
import alleycats.*
import shapeless3.deriving.Const

private[derived] trait Instances extends Instances1:
Expand All @@ -27,3 +28,6 @@ private[derived] trait Instances1:
given [X](using X: Semigroup[X]): SemigroupK[Const[X]] with
def combineK[A](x: Const[X][A], y: Const[X][A]): Const[X][A] =
X.combine(x, y)

given [X](using X: Empty[X]): EmptyK[Const[X]] with
joroKr21 marked this conversation as resolved.
Show resolved Hide resolved
def empty[A]: X = X.empty
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/invariant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Invariant
import shapeless3.deriving.K1

object invariant extends InvariantDerivation, Instances

trait GenericInvariant[T[x[_]] <: Invariant[x], F[_]](using inst: K1.Instances[T, F])
extends Invariant[F]:
def imap[A, B](fa: F[A])(f: A => B)(g: B => A): F[B] = inst.map(fa)(
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/monoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Monoid
import shapeless3.deriving.K0

object monoid extends MonoidDerivation

trait ProductMonoid[F[x] <: Monoid[x], A](
using inst: K0.ProductInstances[F, A]
) extends ProductSemigroup[F, A], Monoid[A]:
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/monoidk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.{Monoid, MonoidK}
import shapeless3.deriving.{Const, K1}

object monoidk extends MonoidKDerivation, Instances

trait ProductMonoidK[T[x[_]] <: MonoidK[x], F[_]](using inst: K1.ProductInstances[T, F])
extends ProductSemigroupK[T, F], MonoidK[F]:
def empty[A]: F[A] = inst.construct([t[_]] => (emp: T[t]) => emp.empty[A])
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/order.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Order
import shapeless3.deriving.{K0, Complete}

object order extends OrderDerivation

trait ProductOrder[T[x] <: Order[x], A](using inst: K0.ProductInstances[T, A])
extends Order[A]:

Expand Down
44 changes: 44 additions & 0 deletions core/src/main/scala-3/cats/derived/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cats.derived

import cats.*

object semiauto extends
CommutativeMonoidDerivation,
CommutativeSemigroupDerivation,
ContravariantDerivation,
EmptyDerivation,
EmptyKDerivation,
EqDerivation,
FoldableDerivation,
FunctorDerivation,
HashDerivation,
InvariantDerivation,
MonoidDerivation,
MonoidKDerivation,
OrderDerivation,
PartialOrderDerivation,
ReducibleDerivation,
SemigroupDerivation,
SemigroupKDerivation,
ShowDerivation,
TraverseDerivation,
Instances:
joroKr21 marked this conversation as resolved.
Show resolved Hide resolved

def foldable[F[_]](using ev: DerivedFoldable[F]): Foldable[F] = ev.instance

def functor[F[_]](using ev: DerivedFunctor[F]): Functor[F] = ev.instance

def reducible[F[_]](using ev: DerivedReducible[F]): Reducible[F] = ev.instance

def traverse[F[_]](using ev: DerivedTraverse[F]): Traverse[F] = ev.instance
joroKr21 marked this conversation as resolved.
Show resolved Hide resolved


object auto:

given [F[_]](using ev: DerivedFoldable[F]): Foldable[F] = ev.instance

given [F[_]](using ev: DerivedFunctor[F]): Functor[F] = ev.instance

given [F[_]](using ev: DerivedReducible[F]): Reducible[F] = ev.instance

given [F[_]](using ev: DerivedTraverse[F]): Traverse[F] = ev.instance
joroKr21 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/partialOrder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.PartialOrder
import shapeless3.deriving.{K0, Complete}

object partialOrder extends PartialOrderDerivation

trait ProductPartialOrder[T[x] <: PartialOrder[x], A](using inst: K0.ProductInstances[T, A])
extends PartialOrder[A]:

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import cats.{Eval, Foldable, Reducible}
import shapeless3.deriving.{Continue, Const, K1}
import scala.compiletime.*

object reducible extends ReducibleDerivation

type DerivedReducible[F[_]] = Derived[Reducible[F]]
object DerivedReducible:
type Or[F[_]] = Derived.Or[Reducible[F]]
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/semigroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Semigroup
import shapeless3.deriving.K0

object semigroup extends SemigroupDerivation

trait ProductSemigroup[F[x] <: Semigroup[x], A](
using inst: K0.ProductInstances[F, A]
) extends Semigroup[A]:
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/semigroupk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.{Semigroup, SemigroupK}
import shapeless3.deriving.{Const, K1}

object semigroupk extends SemigroupKDerivation, Instances

trait ProductSemigroupK[T[x[_]] <: SemigroupK[x], F[_]](using inst: K1.ProductInstances[T, F])
extends SemigroupK[F]:
def combineK[A](x: F[A], y: F[A]): F[A] = inst.map2[A, A, A](x,y)(
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cats.derived
import cats.Show
import shapeless3.deriving.{Continue, K0, Labelling}

object show extends ShowDerivation

trait ShowDerivation:

extension (F: Show.type)
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala-3/cats/derived/traverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import cats.{Applicative, Eval, Traverse}
import shapeless3.deriving.{Const, Continue, K1}
import scala.compiletime.*

object traverse extends TraverseDerivation, Instances

type DerivedTraverse[F[_]] = Derived[Traverse[F]]
object DerivedTraverse:
type Or[F[_]] = Derived.Or[Traverse[F]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cats.derived

import alleycats._
import cats._
import alleycats.*
import cats.*
import cats.kernel.CommutativeMonoid
import cats.derived.all._
import cats.derived.semiauto.*

class CommutativeMonoidTests { //
case class Foo(i: Int, b: Option[Int]) derives CommutativeMonoid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cats.derived

import alleycats._
import cats._
import alleycats.*
import cats.*
import cats.kernel.CommutativeSemigroup
import cats.derived.all._
import cats.derived.semiauto.*

class CommutativeSemigroupTests { //
case class Foo(i: Int, b: Option[Int]) derives CommutativeSemigroup
Expand Down
3 changes: 1 addition & 2 deletions core/src/test/scala-3/cats/derived/ContravariantTests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cats.derived

import cats.Contravariant
import cats.derived.all._
import cats.derived.all.given
import cats.derived.semiauto.*

class ContravariantTests {

Expand Down
10 changes: 5 additions & 5 deletions core/src/test/scala-3/cats/derived/EmptyKTests.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cats.derived

import alleycats._
import alleycats.std.all._
import cats._
import cats.derived.all._
import cats.derived.all.given
import alleycats.*
import alleycats.std.all.*
import cats.*
import cats.derived.semiauto.*
import cats.derived.semiauto.given

class EmptyKTests { //
case class Foo[A](i: String, l: List[A]) derives EmptyK
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/scala-3/cats/derived/EmptyTests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats.derived

import alleycats._
import cats._
import cats.derived.all._
import alleycats.*
import cats.*
import cats.derived.semiauto.*

object EmptyTests:
case class Foo(i: Int, b: IntTree) derives Empty
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/scala-3/cats/derived/EqTests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats.derived

import alleycats._
import cats._
import cats.derived.all._
import alleycats.*
import cats.*
import cats.derived.semiauto.*

class EqTests { //
case class Foo(i: Int, b: Option[String]) derives Eq
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala-3/cats/derived/FoldableTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats.derived

import cats.Foldable
import cats.derived.all._
import cats.derived.semiauto.*

class FoldableTests {

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala-3/cats/derived/FunctorTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats.derived

import cats.Functor
import cats.derived.all._
import cats.derived.semiauto.*

class FunctorTests {

Expand Down
6 changes: 3 additions & 3 deletions core/src/test/scala-3/cats/derived/HashTests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats.derived

import alleycats._
import cats._
import cats.derived.all._
import alleycats.*
import cats.*
import cats.derived.semiauto.*

class HashTests { //
case class Foo(i: Int, b: Option[String]) derives Hash
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala-3/cats/derived/InvariantTests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats.derived

import cats.Invariant
import cats.derived.all._
import cats.derived.all.given
import cats.derived.semiauto.*
import cats.derived.semiauto.given

class InvariantTests {

Expand Down
7 changes: 3 additions & 4 deletions core/src/test/scala-3/cats/derived/MonoidKTests.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package cats.derived

import alleycats._
import cats._
import cats.derived.all._
import cats.derived.all.given
import alleycats.*
import cats.*
import cats.derived.semiauto.*

class MonoidKTests { //
case class Foo[A](i: String, l: List[A]) derives MonoidK
Expand Down
Loading