Created
November 23, 2018 15:21
-
-
Save robhinds/0da338aa9c5656aa0f838d9fef69adec to your computer and use it in GitHub Desktop.
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 | |
implicit val capybaraGenerator = new Generator[Capybara] { | |
override def gen: Capybara = Capybara( | |
name = Random.nextString(10), | |
age = Random.nextInt(50), | |
tasty = Random.nextBoolean() | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment