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 all 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
6 changes: 0 additions & 6 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 Expand Up @@ -51,7 +49,3 @@ object DerivedFoldable:
inst.fold[A, Eval[B]](fa) { [f[_]] => (tf: T[f], fa: f[A]) =>
Eval.defer(tf.foldRight(fa, lb)(f))
}

trait FoldableDerivation:
extension (F: Foldable.type)
inline def derived[F[_]]: Foldable[F] = DerivedFoldable[F]
6 changes: 0 additions & 6 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 All @@ -29,7 +27,3 @@ object DerivedFunctor:
inst.map(fa: F[A]) { [f[_]] => (tf: T[f], fa: f[A]) =>
tf.map(fa)(f)
}

trait FunctorDerivation:
extension (F: Functor.type)
inline def derived[F[_]]: Functor[F] = DerivedFunctor[F]
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
52 changes: 52 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,52 @@
package cats.derived

import cats.*

extension (F: Foldable.type)
inline def derived[F[_]]: Foldable[F] = DerivedFoldable[F]

extension (F: Functor.type)
inline def derived[F[_]]: Functor[F] = DerivedFunctor[F]

extension (F: Reducible.type)
inline def derived[F[_]]: Reducible[F] = DerivedReducible[F]

extension (F: Traverse.type)
inline def derived[F[_]]: Traverse[F] = DerivedTraverse[F]

object semiauto extends
CommutativeMonoidDerivation,
CommutativeSemigroupDerivation,
ContravariantDerivation,
EmptyDerivation,
EmptyKDerivation,
EqDerivation,
HashDerivation,
InvariantDerivation,
MonoidDerivation,
MonoidKDerivation,
OrderDerivation,
PartialOrderDerivation,
SemigroupDerivation,
SemigroupKDerivation,
ShowDerivation,
Instances:

inline def foldable[F[_]]: Foldable[F] = DerivedFoldable[F]

inline def functor[F[_]]: Functor[F] = DerivedFunctor[F]

inline def reducible[F[_]]: Reducible[F] = DerivedReducible[F]

inline def traverse[F[_]]: Traverse[F] = DerivedTraverse[F]


object auto:

inline given [F[_]]: Foldable[F] = DerivedFoldable[F]

inline given [F[_]]: Functor[F] = DerivedFunctor[F]

inline given [F[_]]: Reducible[F] = DerivedReducible[F]

inline given [F[_]]: Traverse[F] = DerivedTraverse[F]
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
6 changes: 0 additions & 6 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 Expand Up @@ -62,7 +60,3 @@ object DerivedReducible:
inst.fold[A, Eval[B]](fa) { [f[_]] => (tf: T[f], fa: f[A]) =>
Eval.defer(tf.reduceRightTo(fa)(f)(g))
}

trait ReducibleDerivation:
extension (F: Reducible.type)
inline def derived[F[_]]: Reducible[F] = DerivedReducible[F]
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
6 changes: 0 additions & 6 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 Expand Up @@ -57,7 +55,3 @@ object DerivedTraverse:
} { [f[_]] => (tf: T[f], fa: f[A]) =>
tf.traverse(fa)(f)
}

trait TraverseDerivation:
extension (F: Traverse.type)
inline def derived[F[_]]: Traverse[F] = DerivedTraverse[F]
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.*

class FoldableTests {

Expand Down
Loading