This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def caseClassGenerator[T, L <: HList](implicit generic: Generic.Aux[T, L], lGen: Generator[L]): Generator[T] = | |
new Generator[T] { | |
override def generate = generic.from(lGen.generate) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val hlistCapy = genericCapybara.to(Generator.generate[Capybara]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
val genericCapybara = Generic[Capybara] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val capybara: String :: Int :: Boolean :: HNil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Capybara(name: String, age: Int, awesome: Boolean) | |
case class Dog(name: String, age: Int, awesome: Boolean) | |
object Generator { | |
import scala.util.Random | |
def generate[A](implicit gen: Generator[A]): A = gen.gen | |
implicit val intGenerator = new Generator[Int]{ | |
override def gen: Int = Random.nextInt(50) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Generator[A] { | |
def gen: A | |
} | |
case class Capybara(name: String, age: Int, awesome: Boolean) | |
object Generator { | |
import scala.util.Random | |
def generate[A](implicit gen: Generator[A]): A = gen.gen | |
implicit val capybaraGenerator = new Generator[Capybara] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Generator[A] { | |
def gen: A | |
} | |
case class Capybara(name: String, age: Int, awesome: Boolean) | |
case class Dog(name: String, age: Int, awesome: Boolean) | |
object Generator { | |
import scala.util.Random |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Generator[A] { | |
def gen: A | |
} | |
case class Capybara(name: String, age: Int, tasty: Boolean) | |
object Generator { | |
import scala.util.Random | |
def generate[A](implicit gen: Generator[A]): A = gen.gen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatest.{FunSpec, Matchers} | |
import shapeless._ | |
sealed trait Parent { | |
def description: Option[String] | |
def another: Option[String] | |
} | |
case class B(description: Option[String], another: Option[String]) extends Parent | |
case class A(description: Option[String], another: Option[String]) extends Parent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Provides a representation of Generic[T], which has a nested Repr type, as a | |
* type with two type parameters instead. | |
* | |
* Here, we specify T, and we find a Generic.Aux[T,R] by implicit search. | |
* We then use R in the second argument. | |
* Generic.Aux[T, R] is exactly equivalent to Generic[T] { type Repr = R }, | |
* but Scala doesn't allow us to write it this way: | |
* | |
* {{{ | |
* def myMethod[T]()(eqGen: Generic[T] { Repr = R }, reqEq: Eq[egGen.Repr) = ??? |