|
Scala example source code file (ScalaCheckBinding.scala)
The ScalaCheckBinding.scala Scala example source codepackage scalaz package scalacheck /** * Type class instances for types from [[https://github.com/rickynils/scalacheck Scalacheck]] */ object ScalaCheckBinding { import org.scalacheck.{Gen, Arbitrary, Shrink} import Gen.{sized, const} implicit val ArbitraryMonad: Monad[Arbitrary] = new Monad[Arbitrary] { def bind[A, B](fa: Arbitrary[A])(f: A => Arbitrary[B]) = Arbitrary(fa.arbitrary.flatMap(f(_).arbitrary)) def point[A](a: => A) = Arbitrary(sized(_ => const(a))) override def map[A, B](fa: Arbitrary[A])(f: A => B) = Arbitrary(fa.arbitrary.map(f)) } implicit val GenMonad: Monad[Gen] = new Monad[Gen] { def point[A](a: => A) = sized(_ => const(a)) def bind[A, B](fa: Gen[A])(f: A => Gen[B]) = fa flatMap f override def map[A, B](fa: Gen[A])(f: A => B) = fa map f } implicit val ShrinkFunctor: InvariantFunctor[Shrink] = new InvariantFunctor[Shrink] { def xmap[A, B](ma: Shrink[A], f: A => B, g: B => A): Shrink[B] = Shrink{b => ma shrink g(b) map f} } } // vim: expandtab:ts=2:sw=2 Other Scala examples (source code examples)Here is a short list of links related to this Scala ScalaCheckBinding.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.