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 route = | |
pathPrefix(“user” / JavaUuid) { userId => | |
pathSingleSlash { | |
get { | |
complete { | |
//fetch user details | |
} | |
} | |
} | |
} |
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 | |
import shapeless.{HList, HNil, _} | |
import scala.util.Random | |
trait Generator[A] { | |
def generate: A | |
} | |
object Generator { |
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 cnilGenerator: Generator[CNil] = | |
new Generator[CNil] { | |
override def generate: CNil = throw new RuntimeException("Invalid candidate configuration") | |
} | |
implicit def cconsGenerator[H, T <: Coproduct] = | |
new Generator[H :+: T] { | |
override def generate = throw new RuntimeException("Invalid candidate configuration") | |
} |
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 Generator._ | |
case class Sample(a: Int, b: Boolean, c: Double, d: String) | |
generate[Sample] |
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 hconsGenerator[H, T <: HList](implicit headGen: Generator[H], tailGen: Generator[T]) = | |
new Generator[H :: T] { | |
override def generate = headGen.generate :: tailGen.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
implicit def hnilGenerator = new Generator[HNil] { | |
override def generate = 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
implicit def genericToGenerator[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
implicit def intGenerator = new Generator[Int] { | |
override def generate = Random.nextInt | |
} | |
implicit def doubleGenerator = new Generator[Double] { | |
override def generate = Random.nextDouble | |
} | |
implicit def StringGenerator = new Generator[String] { | |
val loremWords = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".split(" ") |
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
object Generator { | |
def generate[A](implicit gen: Generator[A]) = gen.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
trait Generator[A] { | |
def generate: A | |
} |