Skip to content

Commit

Permalink
Changed priority and added a test (#2618)
Browse files Browse the repository at this point in the history
  • Loading branch information
barambani authored and Luka Jacobowitz committed Nov 18, 2018
1 parent e1a7cfc commit f2060c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,32 +291,35 @@ sealed abstract private[data] class KleisliInstances4 extends KleisliInstances5
implicit def catsDataSemigroupKForKleisli[F[_], A](implicit F0: SemigroupK[F]): SemigroupK[Kleisli[F, A, ?]] =
new KleisliSemigroupK[F, A] { def F: SemigroupK[F] = F0 }

implicit def catsDataApplicativeErrorForKleisli[F[_], E, A](
implicit F0: ApplicativeError[F, E]
): ApplicativeError[Kleisli[F, A, ?], E] =
new KleisliApplicativeError[F, A, E] { def F: ApplicativeError[F, E] = F0 }

implicit def catsDataFlatMapForKleisli[F[_], A](implicit FM: FlatMap[F]): FlatMap[Kleisli[F, A, ?]] =
new KleisliFlatMap[F, A] { def F: FlatMap[F] = FM }

}

sealed abstract private[data] class KleisliInstances5 extends KleisliInstances6 {

implicit def catsDataApplicativeErrorForKleisli[F[_], E, A](
implicit F0: ApplicativeError[F, E]
): ApplicativeError[Kleisli[F, A, ?], E] =
new KleisliApplicativeError[F, A, E] { def F: ApplicativeError[F, E] = F0 }
}

sealed abstract private[data] class KleisliInstances6 extends KleisliInstances7 {
implicit def catsDataApplicativeForKleisli[F[_], A](implicit A: Applicative[F]): Applicative[Kleisli[F, A, ?]] =
new KleisliApplicative[F, A] { def F: Applicative[F] = A }
}

sealed abstract private[data] class KleisliInstances6 extends KleisliInstances7 {
sealed abstract private[data] class KleisliInstances7 extends KleisliInstances8 {
implicit def catsDataApplyForKleisli[F[_], A](implicit A: Apply[F]): Apply[Kleisli[F, A, ?]] =
new KleisliApply[F, A] { def F: Apply[F] = A }
}

sealed abstract private[data] class KleisliInstances7 extends KleisliInstances8 {
sealed abstract private[data] class KleisliInstances8 extends KleisliInstances9 {
implicit def catsDataDistributiveForKleisli[F[_], R](implicit F0: Distributive[F]): Distributive[Kleisli[F, R, ?]] =
new KleisliDistributive[F, R] with KleisliFunctor[F, R] { implicit def F: Distributive[F] = F0 }
}

sealed abstract private[data] class KleisliInstances8 {
sealed abstract private[data] class KleisliInstances9 {
implicit def catsDataFunctorForKleisli[F[_], A](implicit F0: Functor[F]): Functor[Kleisli[F, A, ?]] =
new KleisliFunctor[F, A] { def F: Functor[F] = F0 }
}
Expand Down
5 changes: 5 additions & 0 deletions tests/src/test/scala/cats/tests/KleisliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class KleisliSuite extends CatsSuite {
checkAll("Contravariant[Kleisli[Option, ?, Int]]",
SerializableTests.serializable(Contravariant[Kleisli[Option, ?, Int]]))

test("Functor[Kleisli[F, Int, ?]] is not ambiguous when an ApplicativeError and a FlatMap are in scope for F") {
def shouldCompile1[F[_]: ApplicativeError[?[_], E]: FlatMap, E]: Functor[Kleisli[F, Int, ?]] =
Functor[Kleisli[F, Int, ?]]
}

test("local composes functions") {
forAll { (f: Int => Option[String], g: Int => Int, i: Int) =>
f(g(i)) should ===(Kleisli.local[Option, String, Int](g)(Kleisli(f)).run(i))
Expand Down

0 comments on commit f2060c3

Please sign in to comment.