Skip to content

Commit

Permalink
Allow non-constant arbitrary functions for (Co)Kleisli, State, Func
Browse files Browse the repository at this point in the history
Resolves typelevel#1605.

This is a replacement for typelevel#1606.
  • Loading branch information
ceedubs committed Apr 21, 2017
1 parent c1dcd40 commit 2ec0815
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions laws/src/main/scala/cats/laws/discipline/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ object arbitrary extends ArbitraryInstances0 {
(a, b) => A.perturb(B.perturb(seed, b), a)))


implicit def catsLawsArbitraryForCokleisli[F[_], A, B](implicit B: Arbitrary[B]): Arbitrary[Cokleisli[F, A, B]] =
Arbitrary(B.arbitrary.map(b => Cokleisli[F, A, B](_ => b)))
implicit def catsLawsArbitraryForCokleisli[F[_], A, B](implicit FAB: Arbitrary[F[A] => B]): Arbitrary[Cokleisli[F, A, B]] =
Arbitrary(FAB.arbitrary.map(Cokleisli(_)))

implicit def catsLawsArbitraryForOptionT[F[_], A](implicit F: Arbitrary[F[Option[A]]]): Arbitrary[OptionT[F, A]] =
Arbitrary(F.arbitrary.map(OptionT.apply))
Expand All @@ -104,11 +104,11 @@ object arbitrary extends ArbitraryInstances0 {
implicit def catsLawsArbitraryForTuple2K[F[_], G[_], A](implicit F: Arbitrary[F[A]], G: Arbitrary[G[A]]): Arbitrary[Tuple2K[F, G, A]] =
Arbitrary(F.arbitrary.flatMap(fa => G.arbitrary.map(ga => Tuple2K[F, G, A](fa, ga))))

implicit def catsLawsArbitraryForFunc[F[_], A, B](implicit F: Arbitrary[F[B]]): Arbitrary[Func[F, A, B]] =
Arbitrary(F.arbitrary.map(fb => Func.func[F, A, B](_ => fb)))
implicit def catsLawsArbitraryForFunc[F[_], A, B](implicit AFB: Arbitrary[A => F[B]]): Arbitrary[Func[F, A, B]] =
Arbitrary(AFB.arbitrary.map(Func.func(_)))

implicit def catsLawsArbitraryForAppFunc[F[_], A, B](implicit F: Arbitrary[F[B]], FF: Applicative[F]): Arbitrary[AppFunc[F, A, B]] =
Arbitrary(F.arbitrary.map(fb => Func.appFunc[F, A, B](_ => fb)))
implicit def catsLawsArbitraryForAppFunc[F[_], A, B](implicit AFB: Arbitrary[A => F[B]], FF: Applicative[F]): Arbitrary[AppFunc[F, A, B]] =
Arbitrary(AFB.arbitrary.map(Func.appFunc(_)))

implicit def catsLawsArbitraryForWriter[L:Arbitrary, V:Arbitrary]: Arbitrary[Writer[L, V]] =
catsLawsArbitraryForWriterT[Id, L, V]
Expand Down Expand Up @@ -156,10 +156,10 @@ object arbitrary extends ArbitraryInstances0 {
implicit def catsLawsArbitraryForNested[F[_], G[_], A](implicit FG: Arbitrary[F[G[A]]]): Arbitrary[Nested[F, G, A]] =
Arbitrary(FG.arbitrary.map(Nested(_)))

implicit def catsLawArbitraryForState[S: Arbitrary: Cogen, A: Arbitrary]: Arbitrary[State[S, A]] =
implicit def catsLawArbitraryForState[S, A](implicit SSA: Arbitrary[S => Eval[(S, A)]]): Arbitrary[State[S, A]] =
catsLawArbitraryForStateT[Eval, S, A]

implicit def catsLawArbitraryForReader[A: Arbitrary, B: Arbitrary]: Arbitrary[Reader[A, B]] =
implicit def catsLawArbitraryForReader[A, B](implicit AB: Arbitrary[A => B]): Arbitrary[Reader[A, B]] =
catsLawsArbitraryForKleisli[Id, A, B]
}

Expand All @@ -174,7 +174,7 @@ private[discipline] sealed trait ArbitraryInstances0 {
implicit def catsLawsCogenForWriterT[F[_], L, V](implicit F: Cogen[F[(L, V)]]): Cogen[WriterT[F, L, V]] =
F.contramap(_.run)

implicit def catsLawsArbitraryForKleisli[F[_], A, B](implicit F: Arbitrary[F[B]]): Arbitrary[Kleisli[F, A, B]] =
Arbitrary(F.arbitrary.map(fb => Kleisli[F, A, B](_ => fb)))
implicit def catsLawsArbitraryForKleisli[F[_], A, B](implicit AFB: Arbitrary[A => F[B]]): Arbitrary[Kleisli[F, A, B]] =
Arbitrary(AFB.arbitrary.map(Kleisli(_)))

}

0 comments on commit 2ec0815

Please sign in to comment.