/magnolify

A collection of Magnolia add-on modules

Primary LanguageScalaApache License 2.0Apache-2.0

magnolify

Build Status codecov.io GitHub license Maven Central Scala Steward badge

A collection of Magnolia add-on modules, a simpler and faster successor to shapeless-datatype.

Modules

This library includes the following modules.

  • magnolify-cats - type class derivation for Cats Eq[T], Hash[T], Semigroup[T], Monoid[T], Group[T], etc.
  • magnolify-scalacheck - type class derivation for ScalaCheck Arbitrary[T], Cogen[T], etc.
  • magnolify-guava - type class derivation for Guava Funnel[T], etc.
  • magnolify-avro - conversion between Scala case classes and Apache Avro GenericRecord
  • magnolify-bigquery - conversion between Scala case classes and Google Cloud BigQuery TableRow
  • magnolify-datastore - conversion between Scala case classes and Google Cloud Datastore Entity
  • magnolify-tensorflow - conversion between Scala case classes and TensorFlow Example

Usage

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) 

License

Copyright 2019 Spotify AB.

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0