diff --git a/cats/src/main/scala-2/magnolify/cats/CatsImplicits.scala b/cats/src/main/scala-2/magnolify/cats/CatsImplicits.scala new file mode 100644 index 000000000..4afba1bea --- /dev/null +++ b/cats/src/main/scala-2/magnolify/cats/CatsImplicits.scala @@ -0,0 +1,61 @@ +/* + * Copyright 2023 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package magnolify.cats + +import cats.Show +import cats.kernel.* + +trait CatsImplicits { + implicit def genBand(b: Band.type): magnolify.cats.BandDerivation.type = + magnolify.cats.BandDerivation + + implicit def genCommutativeGroup( + cg: CommutativeGroup.type + ): magnolify.cats.CommutativeGroupDerivation.type = + magnolify.cats.CommutativeGroupDerivation + + implicit def genCommutativeMonoid( + cm: CommutativeMonoid.type + ): magnolify.cats.CommutativeMonoidDerivation.type = + magnolify.cats.CommutativeMonoidDerivation + + implicit def genCommutativeSemigroup( + cm: CommutativeSemigroup.type + ): magnolify.cats.CommutativeSemigroupDerivation.type = + magnolify.cats.CommutativeSemigroupDerivation + + implicit def genEq(eq: Eq.type): magnolify.cats.EqDerivation.type = + magnolify.cats.EqDerivation + + implicit def genGroup(g: Group.type): magnolify.cats.GroupDerivation.type = + magnolify.cats.GroupDerivation + + implicit def genHash(h: Hash.type): magnolify.cats.HashDerivation.type = + magnolify.cats.HashDerivation + + implicit def genMonoid(m: Monoid.type): magnolify.cats.MonoidDerivation.type = + magnolify.cats.MonoidDerivation + + implicit def genSemigroup(sg: Semigroup.type): magnolify.cats.SemigroupDerivation.type = + magnolify.cats.SemigroupDerivation + + implicit def genShow(sg: Show.type): magnolify.cats.ShowDerivation.type = + magnolify.cats.ShowDerivation + +} + +object CatsImplicits diff --git a/cats/src/main/scala-3/magnolify/cats/CatsImplicits.scala b/cats/src/main/scala-3/magnolify/cats/CatsImplicits.scala new file mode 100644 index 000000000..bbf24859c --- /dev/null +++ b/cats/src/main/scala-3/magnolify/cats/CatsImplicits.scala @@ -0,0 +1,47 @@ +/* + * Copyright 2023 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package magnolify.cats + +import cats.Show +import cats.kernel.* + +import scala.deriving.Mirror + +trait CatsImplicits: + + // format: off + extension (b: Band.type) inline def gen[T](using Mirror.Of[T]): Band[T] = BandDerivation.gen + extension (cg: CommutativeGroup.type) inline def gen[T](using Mirror.Of[T]): CommutativeGroup[T] = CommutativeGroupDerivation.gen + + extension (cm: CommutativeMonoid.type) inline def gen[T](using Mirror.Of[T]): CommutativeMonoid[T] = CommutativeMonoidDerivation.gen + + extension (cm: CommutativeSemigroup.type) inline def gen[T](using Mirror.Of[T]): CommutativeSemigroup[T] = CommutativeSemigroupDerivation.gen + + extension (eq: Eq.type) inline def gen[T](using Mirror.Of[T]): Eq[T] = EqDerivation.gen + + extension (g: Group.type) inline def gen[T](using Mirror.Of[T]): Group[T] = GroupDerivation.gen + + extension (h: Hash.type) inline def gen[T](using Mirror.Of[T]): Hash[T] = HashDerivation.gen + + extension (m: Monoid.type) inline def gen[T](using Mirror.Of[T]): Monoid[T] = MonoidDerivation.gen + + extension (sg: Semigroup.type) inline def gen[T](using Mirror.Of[T]): Semigroup[T] = SemigroupDerivation.gen + + extension (s: Show.type) inline def gen[T](using Mirror.Of[T]): Show[T] = ShowDerivation.gen + // format: on + +object CatsImplicits diff --git a/cats/src/main/scala/magnolify/cats/auto/package.scala b/cats/src/main/scala/magnolify/cats/auto/package.scala index 34ed249a0..29805d5ff 100644 --- a/cats/src/main/scala/magnolify/cats/auto/package.scala +++ b/cats/src/main/scala/magnolify/cats/auto/package.scala @@ -16,4 +16,4 @@ package magnolify.cats -package object auto extends AutoDerivation +package object auto extends CatsImplicits with AutoDerivation diff --git a/cats/src/main/scala/magnolify/cats/semiauto/package.scala b/cats/src/main/scala/magnolify/cats/semiauto/package.scala index 888f346d0..5cc593e6f 100644 --- a/cats/src/main/scala/magnolify/cats/semiauto/package.scala +++ b/cats/src/main/scala/magnolify/cats/semiauto/package.scala @@ -16,10 +16,7 @@ package magnolify.cats -import cats.Show -import cats.kernel.* - -package object semiauto { +package object semiauto extends CatsImplicits { @deprecated("Use Band.gen[T] instead", "0.7.0") val BandDerivation = magnolify.cats.BandDerivation @@ -39,30 +36,5 @@ package object semiauto { val SemigroupDerivation = magnolify.cats.SemigroupDerivation @deprecated("Use Show.gen[T] instead", "0.7.0") val ShowDerivation = magnolify.cats.ShowDerivation - implicit def genBand(b: Band.type): magnolify.cats.BandDerivation.type = - magnolify.cats.BandDerivation - implicit def genCommutativeGroup( - cg: CommutativeGroup.type - ): magnolify.cats.CommutativeGroupDerivation.type = - magnolify.cats.CommutativeGroupDerivation - implicit def genCommutativeMonoid( - cm: CommutativeMonoid.type - ): magnolify.cats.CommutativeMonoidDerivation.type = - magnolify.cats.CommutativeMonoidDerivation - implicit def genCommutativeSemigroup( - cm: CommutativeSemigroup.type - ): magnolify.cats.CommutativeSemigroupDerivation.type = - magnolify.cats.CommutativeSemigroupDerivation - implicit def genEq(eq: Eq.type): magnolify.cats.EqDerivation.type = - magnolify.cats.EqDerivation - implicit def genGroup(g: Group.type): magnolify.cats.GroupDerivation.type = - magnolify.cats.GroupDerivation - implicit def genHash(h: Hash.type): magnolify.cats.HashDerivation.type = - magnolify.cats.HashDerivation - implicit def genMonoid(m: Monoid.type): magnolify.cats.MonoidDerivation.type = - magnolify.cats.MonoidDerivation - implicit def genSemigroup(sg: Semigroup.type): magnolify.cats.SemigroupDerivation.type = - magnolify.cats.SemigroupDerivation - implicit def genShow(sg: Show.type): magnolify.cats.ShowDerivation.type = - magnolify.cats.ShowDerivation + }