A collection of Magnolia add-on modules, a simpler and faster successor to shapeless-datatype.
This library includes the following modules.
magnolify-cats
- type class derivation for CatsEq[T]
,Hash[T]
,Semigroup[T]
,Monoid[T]
,Group[T]
, etc.magnolify-scalacheck
- type class derivation for ScalaCheckArbitrary[T]
,Cogen[T]
, etc.magnolify-guava
- type class derivation for GuavaFunnel[T]
, etc.magnolify-avro
- conversion between Scala case classes and Apache AvroGenericRecord
magnolify-bigquery
- conversion between Scala case classes and Google Cloud BigQueryTableRow
magnolify-datastore
- conversion between Scala case classes and Google Cloud DatastoreEntity
magnolify-tensorflow
- conversion between Scala case classes and TensorFlowExample
Cats and ScalaCheck type class derivation can be performed both automatically and semi-automatically.
import magnolify.cats.auto._
implicitly[Eq[MyCaseClass]]
implicitly[Hash[MyCaseClass]]
import magnolify.scalacheck.auto._
implicitly[Arbitrary[MyCaseClass]]
implicitly[Cogen[MyCaseClass]]
import magnolify.guava.auto._
implicitly[Funnel[MyCaseClass]]
import magnolify.cats.semiauto._
EqDerivation[MyCaseClass]
HashDerivation[MyCaseClass]
SemigroupDerivation[MyCaseClass]
MonoidDerivation[MyCaseClass]
GroupDerivation[MyCaseClass]
import magnolify.scalacheck.semiauto._
ArbitraryDerivation[MyCaseClass]
CogenDerivation[MyCaseClass]
import magnolify.guava.semiauto._
FunnelDerivation[MyCaseClass]
Case class type conversion must be done explicitly.
import magnolify.avro._
val t = AvroType[MyCaseClass]
val r = t.to(MyCaseClass(...))
val c = t.from(t)
t.schema // Avro Schema
implicit val uriField = AvroField.from[String](URI.create)(_.toString) // custom field type
import magnolify.bigquery._
val t = TableRowType[MyCaseClass]
val r = t.to(MyCaseClass(...))
val c = t.from(t)
t.schema // BigQuery TableSchema
implicit val uriField = TableRowField.from[String](URI.create)(_.toString) // custom field type
import magnolify.datastore._
val t = EntityType[MyCaseClass]
val r = t.to(MyCaseClass(...))
val c = t.from(t)
implicit val uriField = EntityField.from[String](URI.create)(_.toString) // custom field type
import magnolify.tensorflow._
val t = ExampleType[MyCaseClass]
val r = t.to(MyCaseClass(...))
val c = t.from(t)
// custom field type
implicit val stringField = ExampleField.from[ByteString](_.toStringUtf8)(ByteString.copyFromUtf8)
Copyright 2019 Spotify AB.
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0