Skip to content

Commit

Permalink
Streamline auto api
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Jul 18, 2022
1 parent 4228876 commit 884818b
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 44 deletions.
4 changes: 2 additions & 2 deletions avro/src/main/scala-2/magnolify/avro/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package magnolify.avro

import magnolify.avro.auto.AvroMacros

package object auto extends AutoDerivation with AvroImplicits
package object auto extends AutoDerivation

trait AutoDerivation {
implicit def genAvroField[T]: AvroField.Record[T] = macro AvroMacros.genAvroFieldMacro[T]
implicit def derivedAvroField[T]: AvroField.Record[T] = macro AvroMacros.genAvroFieldMacro[T]
}
4 changes: 2 additions & 2 deletions avro/src/main/scala-3/magnolify/avro/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import magnolify.avro.semiauto.AvroFieldDerivation

import scala.deriving.Mirror

package object auto extends AutoDerivation with AvroImplicits
package object auto extends AutoDerivation

trait AutoDerivation:
inline given autoDerivedAvroField[T](using Mirror.Of[T]): AvroField.Record[T] =
inline given derivedAvroField[T](using Mirror.Of[T]): AvroField.Record[T] =
AvroFieldDerivation[T]
19 changes: 19 additions & 0 deletions avro/src/main/scala/magnolify/avro/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 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

package object avro extends AvroImplicits
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class AvroTypeSuite
// Enum types would be derived several times if not stored
implicit val etJava: EnumType[JavaEnums.Color] = javaEnumType[JavaEnums.Color]
implicit val etScala: EnumType[ScalaEnums.Color.Type] = scalaEnumType[ScalaEnums.Color.Type]
implicit val etAdt: EnumType[ADT.Color] = autoDerivedEnumType[ADT.Color]
implicit val etAdt: EnumType[ADT.Color] = derivedEnumType[ADT.Color]

implicit val afUri: AvroField[URI] = AvroField.from[String](URI.create)(_.toString)
implicit val afDuration: AvroField[Duration] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package magnolify.bigquery

import magnolify.bigquery.auto.BigQueryMacros

package object auto extends AutoDerivation with BigQueryImplicits
package object auto extends AutoDerivation

trait AutoDerivation {
implicit def genTableRowField[T]: TableRowField.Record[T] =
implicit def derivedTableRowField[T]: TableRowField.Record[T] =
macro BigQueryMacros.genTableRowFieldMacro[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import magnolify.bigquery.semiauto.TableRowFieldDerivation

import scala.deriving.Mirror

package object auto extends AutoDerivation with BigQueryImplicits
package object auto extends AutoDerivation

trait AutoDerivation:
inline given autoDerivedTableRowField[T](using Mirror.Of[T]): TableRowField.Record[T] =
inline given derivedTableRowField[T](using Mirror.Of[T]): TableRowField.Record[T] =
TableRowFieldDerivation[T]
19 changes: 19 additions & 0 deletions bigquery/src/main/scala/magnolify/bigquery/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 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

package object bigquery extends BigQueryImplicits
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package magnolify.bigtable

import magnolify.bigtable.auto.BigtableMacros

package object auto extends AutoDerivation with BigtableImplicits
package object auto extends AutoDerivation

trait AutoDerivation {
implicit def genBigtableField[T]: BigtableField.Record[T] =
implicit def derivedBigtableField[T]: BigtableField.Record[T] =
macro BigtableMacros.genBigtableFielddMacro[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import magnolify.bigtable.semiauto.BigtableFieldDerivation

import scala.deriving.Mirror

package object auto extends AutoDerivation with BigtableImplicits
package object auto extends AutoDerivation

trait AutoDerivation {
inline given autoDerivedBigtableField[T](using Mirror.Of[T]): BigtableField.Record[T] =
inline given derivedBigtableField[T](using Mirror.Of[T]): BigtableField.Record[T] =
BigtableFieldDerivation[T]
}
19 changes: 19 additions & 0 deletions bigtable/src/main/scala/magnolify/bigtable/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 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

package object bigtable extends BigtableImplicits
23 changes: 13 additions & 10 deletions cats/src/main/scala-2/magnolify/cats/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,41 @@ package object auto extends AutoDerivation

trait AutoDerivation {
// Hash <: Eq
implicit def genHash[T](implicit lp: shapeless.LowPriority): Hash[T] =
implicit def derivedHash[T](implicit lp: shapeless.LowPriority): Hash[T] =
macro CatsMacros.genHashMacro[T]
implicit def genEq[T](implicit lp: shapeless.LowPriority): Eq[T] = macro CatsMacros.genEqMacro[T]
implicit def genShow[T](implicit lp: shapeless.LowPriority): Show[T] =
implicit def derivedEq[T](implicit lp: shapeless.LowPriority): Eq[T] =
macro CatsMacros.genEqMacro[T]
implicit def derivedShow[T](implicit lp: shapeless.LowPriority): Show[T] =
macro CatsMacros.genShowMacro[T]

// CommutativeGroup <: Group | CommutativeMonoid
implicit def genCommutativeGroup[T](implicit lp: shapeless.LowPriority): CommutativeGroup[T] =
implicit def derivedCommutativeGroup[T](implicit lp: shapeless.LowPriority): CommutativeGroup[T] =
macro CatsMacros.genCommutativeGroupMacro[T]

// Group <: Monoid
implicit def genGroup[T](implicit lp: shapeless.LowPriority): Group[T] =
implicit def derivedGroup[T](implicit lp: shapeless.LowPriority): Group[T] =
macro CatsMacros.genGroupMacro[T]

// CommutativeMonoid <: Monoid | CommutativeSemigroup
implicit def genCommutativeMonoid[T](implicit lp: shapeless.LowPriority): CommutativeMonoid[T] =
implicit def derivedCommutativeMonoid[T](implicit
lp: shapeless.LowPriority
): CommutativeMonoid[T] =
macro CatsMacros.genCommutativeMonoidMacro[T]

// Monoid <: Semigroup
implicit def genMonoid[T](implicit lp: shapeless.LowPriority): Monoid[T] =
implicit def derivedMonoid[T](implicit lp: shapeless.LowPriority): Monoid[T] =
macro CatsMacros.genMonoidMacro[T]

// Band <: Semigroup
implicit def genBand[T](implicit lp: shapeless.LowPriority): Band[T] =
implicit def derivedBand[T](implicit lp: shapeless.LowPriority): Band[T] =
macro CatsMacros.genBandMacro[T]

// CommutativeSemigroup <: Semigroup
implicit def genCommutativeSemigroup[T](implicit
implicit def derivedCommutativeSemigroup[T](implicit
lp: shapeless.LowPriority
): CommutativeSemigroup[T] =
macro CatsMacros.genCommutativeSemigroupMacro[T]

implicit def genSemigroup[T](implicit lp: shapeless.LowPriority): Semigroup[T] =
implicit def derivedSemigroup[T](implicit lp: shapeless.LowPriority): Semigroup[T] =
macro CatsMacros.genSemigroupMacro[T]
}
20 changes: 10 additions & 10 deletions cats/src/main/scala-3/magnolify/cats/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ package object auto extends AutoDerivation
trait AutoDerivation extends Priority0AutoDerivation

trait Priority0AutoDerivation extends Priority1AutoDerivation:
inline given autoDerivedEq[T](using Mirror.Of[T]): Eq[T] = EqDerivation[T]
inline given autoDerivedSemigroup[T](using Mirror.Of[T]): Semigroup[T] = SemigroupDerivation[T]
inline given autoDerivedShow[T](using Mirror.Of[T]): Show[T] = ShowDerivation[T]
inline given derivedEq[T](using Mirror.Of[T]): Eq[T] = EqDerivation[T]
inline given derivedSemigroup[T](using Mirror.Of[T]): Semigroup[T] = SemigroupDerivation[T]
inline given derivedShow[T](using Mirror.Of[T]): Show[T] = ShowDerivation[T]

trait Priority1AutoDerivation extends Priority2AutoDerivation:
// Hash <: Eq
inline given autoDerivedHash[T](using Mirror.Of[T]): Hash[T] = HashDerivation[T]
inline given derivedHash[T](using Mirror.Of[T]): Hash[T] = HashDerivation[T]
// CommutativeSemigroup <: Semigroup
inline given autoDerivedCommutativeSemigroup[T](using Mirror.Of[T]): CommutativeSemigroup[T] =
inline given derivedCommutativeSemigroup[T](using Mirror.Of[T]): CommutativeSemigroup[T] =
CommutativeSemigroupDerivation[T]
trait Priority2AutoDerivation extends Priority3AutoDerivation:
// Band <: Semigroup
inline given autoDerivedBand[T](using Mirror.Of[T]): Band[T] = BandDerivation[T]
inline given derivedBand[T](using Mirror.Of[T]): Band[T] = BandDerivation[T]

trait Priority3AutoDerivation extends Priority4AutoDerivation:
// Monoid <: Semigroup
inline given autoDerivedMonoid[T](using Mirror.Of[T]): Monoid[T] = MonoidDerivation[T]
inline given derivedMonoid[T](using Mirror.Of[T]): Monoid[T] = MonoidDerivation[T]

trait Priority4AutoDerivation extends Priority5AutoDerivation:
// CommutativeMonoid <: Monoid | CommutativeSemigroup
inline given autoDerivedCommutativeMonoid[T](using Mirror.Of[T]): CommutativeMonoid[T] =
inline given derivedCommutativeMonoid[T](using Mirror.Of[T]): CommutativeMonoid[T] =
CommutativeMonoidDerivation[T]

trait Priority5AutoDerivation extends Priority6AutoDerivation:
// Group <: Monoid
inline given autoDerivedGroup[T](using Mirror.Of[T]): Group[T] = GroupDerivation[T]
inline given derivedGroup[T](using Mirror.Of[T]): Group[T] = GroupDerivation[T]

trait Priority6AutoDerivation:
// CommutativeGroup <: Group | CommutativeMonoid
inline given autoDerivedCommutativeGroup[T](using Mirror.Of[T]): CommutativeGroup[T] =
inline given derivedCommutativeGroup[T](using Mirror.Of[T]): CommutativeGroup[T] =
CommutativeGroupDerivation[T]
4 changes: 2 additions & 2 deletions guava/src/main/scala-3/magnolify/guava/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import magnolify.guava.semiauto.FunnelDerivation

import scala.deriving.Mirror

package object auto extends AutoDerivation with FunnelImplicits
package object auto extends AutoDerivation

trait AutoDerivation:
inline given autoDerivedFunnel[T](using Mirror.Of[T]): Funnel[T] = FunnelDerivation[T]
inline given derivedFunnel[T](using Mirror.Of[T]): Funnel[T] = FunnelDerivation[T]
19 changes: 19 additions & 0 deletions guava/src/main/scala/magnolify/guava/guava.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 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

package object guava extends FunnelImplicits
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ import org.scalacheck.rng.Seed
package object auto extends AutoDerivation

trait AutoDerivation {
implicit val seedArbitrary: Arbitrary[Seed] = Arbitrary(
Arbitrary.arbLong.arbitrary.map(Seed.apply)
)
implicit val arbSeed: Arbitrary[Seed] = Arbitrary(Arbitrary.arbLong.arbitrary.map(Seed.apply))

implicit def genArbitrary[T]: Arbitrary[T] = macro ScalacheckMacros.genArbitraryMacro[T]
implicit def genCogen[T]: Cogen[T] = macro ScalacheckMacros.genCogenMacro[T]
implicit def derivedArbitrary[T]: Arbitrary[T] = macro ScalacheckMacros.genArbitraryMacro[T]
implicit def derivedCogen[T]: Cogen[T] = macro ScalacheckMacros.genCogenMacro[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ package object auto extends AutoDerivation
trait AutoDerivation: // extends FallbackDerivation:
given arbSeed: Arbitrary[Seed] = Arbitrary(Arbitrary.arbLong.arbitrary.map(Seed.apply))

inline given autoDerivedArbitrary[T](using Mirror.Of[T]): Arbitrary[T] = ArbitraryDerivation[T]
inline given autoDerivedCogen[T](using Mirror.Of[T]): Cogen[T] = CogenDerivation[T]
inline given derivedArbitrary[T](using Mirror.Of[T]): Arbitrary[T] = ArbitraryDerivation[T]
inline given derivedCogen[T](using Mirror.Of[T]): Cogen[T] = CogenDerivation[T]
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import magnolify.shared.auto.EnumMacros
package object auto extends AutoDerivation with EnumImplicits

trait AutoDerivation {
implicit def genEnumType[T]: EnumType[T] = macro EnumMacros.genEnumTypeMacro[T]
implicit def derivedEnumType[T]: EnumType[T] = macro EnumMacros.genEnumTypeMacro[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ import scala.deriving.Mirror
package object auto extends AutoDerivation with EnumImplicits

trait AutoDerivation:
inline given autoDerivedEnumType[T](using Mirror.Of[T]): EnumType[T] = EnumTypeDerivation[T]
inline given derivedEnumType[T](using Mirror.Of[T]): EnumType[T] = EnumTypeDerivation[T]

0 comments on commit 884818b

Please sign in to comment.