Skip to content

Commit

Permalink
Ported over from typelevel#409 by @ceedubs.
Browse files Browse the repository at this point in the history
Originally was 9cb7319.
  • Loading branch information
non committed Aug 7, 2019
1 parent 1d25fcc commit 1089f71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private[scalacheck] sealed trait ArbitraryLowPriority {

/** Arbitrary instance of the Either type */
implicit def arbEither[T, U](implicit at: Arbitrary[T], au: Arbitrary[U]): Arbitrary[Either[T, U]] =
Arbitrary(oneOf(arbitrary[T].map(Left(_)), arbitrary[U].map(Right(_))))
Arbitrary(Gen.either(at.arbitrary, au.arbitrary))

/** Arbitrary instance of the Future type */
implicit def arbFuture[T](implicit a: Arbitrary[T]): Arbitrary[Future[T]] =
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ object Gen extends GenArities with GenVersionSpecific {
def some[T](g: Gen[T]): Gen[Option[T]] =
g.map(Some.apply)

/** Generates a `Left` of `T` or a `Right` of `U` with equal probability. */
def either[T, U](gt: Gen[T], gu: Gen[U]): Gen[Either[T, U]] =
oneOf(gt.map(Left(_)), gu.map(Right(_)))

/** Chooses one of the given generators with a weighted random distribution */
def frequency[T](gs: (Int, Gen[T])*): Gen[T] = {
val filtered = gs.iterator.filter(_._1 > 0).toVector
Expand Down

0 comments on commit 1089f71

Please sign in to comment.