From 3e1a053d1f3a8b1d86972099429f297d34ba0e09 Mon Sep 17 00:00:00 2001 From: "Kai(luo) Wang" Date: Sat, 9 Dec 2017 22:37:25 -0500 Subject: [PATCH] Add `Endo` type alias for (`A =>A`) (#2076) * added reduceRightK and Endo * added mima excpetion * removed reduceRightK * minor --- core/src/main/scala/cats/instances/function.scala | 2 +- core/src/main/scala/cats/package.scala | 1 + tests/src/test/scala/cats/tests/CategorySuite.scala | 1 - tests/src/test/scala/cats/tests/ComposeSuite.scala | 1 - tests/src/test/scala/cats/tests/FoldableSuite.scala | 4 +++- tests/src/test/scala/cats/tests/ReducibleSuite.scala | 6 ++++-- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/cats/instances/function.scala b/core/src/main/scala/cats/instances/function.scala index f6841aab70..19bbd678e9 100644 --- a/core/src/main/scala/cats/instances/function.scala +++ b/core/src/main/scala/cats/instances/function.scala @@ -88,7 +88,7 @@ private[instances] sealed trait Function1Instances extends Function1Instances0 { def compose[A, B, C](f: B => C, g: A => B): A => C = f.compose(g) } - implicit val catsStdMonoidKForFunction1: MonoidK[λ[α => Function1[α, α]]] = + implicit val catsStdMonoidKForFunction1: MonoidK[Endo] = Category[Function1].algebraK } diff --git a/core/src/main/scala/cats/package.scala b/core/src/main/scala/cats/package.scala index 46a24e9837..cab9ea844f 100644 --- a/core/src/main/scala/cats/package.scala +++ b/core/src/main/scala/cats/package.scala @@ -32,6 +32,7 @@ package object cats { * encodes pure unary function application. */ type Id[A] = A + type Endo[A] = A => A implicit val catsInstancesForId: Bimonad[Id] with CommutativeMonad[Id] with Comonad[Id] with NonEmptyTraverse[Id] = new Bimonad[Id] with CommutativeMonad[Id] with Comonad[Id] with NonEmptyTraverse[Id] { def pure[A](a: A): A = a diff --git a/tests/src/test/scala/cats/tests/CategorySuite.scala b/tests/src/test/scala/cats/tests/CategorySuite.scala index d4e215d997..5eb98a484b 100644 --- a/tests/src/test/scala/cats/tests/CategorySuite.scala +++ b/tests/src/test/scala/cats/tests/CategorySuite.scala @@ -9,7 +9,6 @@ import cats.laws.discipline.eq.catsLawsEqForFn1 class CategorySuite extends CatsSuite { val functionCategory = Category[Function1] - type Endo[A] = Function1[A, A] checkAll("Category[Function1].algebraK", MonoidKTests[Endo](functionCategory.algebraK).monoidK[Int]) checkAll("Category[Function1].algebraK", SerializableTests.serializable(functionCategory.algebraK)) diff --git a/tests/src/test/scala/cats/tests/ComposeSuite.scala b/tests/src/test/scala/cats/tests/ComposeSuite.scala index 10f839f893..1c6ca48343 100644 --- a/tests/src/test/scala/cats/tests/ComposeSuite.scala +++ b/tests/src/test/scala/cats/tests/ComposeSuite.scala @@ -8,7 +8,6 @@ import cats.laws.discipline.eq.catsLawsEqForFn1 class ComposeSuite extends CatsSuite { val functionCompose = Compose[Function1] - type Endo[A] = Function1[A, A] checkAll("Compose[Function1].algebraK", SemigroupKTests[Endo](functionCompose.algebraK).semigroupK[Int]) checkAll("Compose[Function1].algebraK", SerializableTests.serializable(functionCompose.algebraK)) diff --git a/tests/src/test/scala/cats/tests/FoldableSuite.scala b/tests/src/test/scala/cats/tests/FoldableSuite.scala index 487e8f32f2..7928469ad0 100644 --- a/tests/src/test/scala/cats/tests/FoldableSuite.scala +++ b/tests/src/test/scala/cats/tests/FoldableSuite.scala @@ -9,7 +9,9 @@ import cats.instances.all._ import cats.data._ import cats.laws.discipline.arbitrary._ -abstract class FoldableSuite[F[_]: Foldable](name: String)(implicit ArbFInt: Arbitrary[F[Int]], ArbFString: Arbitrary[F[String]]) extends CatsSuite with PropertyChecks { +abstract class FoldableSuite[F[_]: Foldable](name: String)( + implicit ArbFInt: Arbitrary[F[Int]], + ArbFString: Arbitrary[F[String]]) extends CatsSuite with PropertyChecks { def iterator[T](fa: F[T]): Iterator[T] diff --git a/tests/src/test/scala/cats/tests/ReducibleSuite.scala b/tests/src/test/scala/cats/tests/ReducibleSuite.scala index a92fdd25b5..b7d3afe4f5 100644 --- a/tests/src/test/scala/cats/tests/ReducibleSuite.scala +++ b/tests/src/test/scala/cats/tests/ReducibleSuite.scala @@ -2,7 +2,6 @@ package cats package tests import org.scalacheck.Arbitrary - import cats.data.NonEmptyList class ReducibleSuiteAdditional extends CatsSuite { @@ -71,7 +70,10 @@ class ReducibleSuiteAdditional extends CatsSuite { } -abstract class ReducibleSuite[F[_]: Reducible](name: String)(implicit ArbFInt: Arbitrary[F[Int]], ArbFString: Arbitrary[F[String]]) extends FoldableSuite[F](name) { +abstract class ReducibleSuite[F[_]: Reducible](name: String)( + implicit ArbFInt: Arbitrary[F[Int]], + ArbFString: Arbitrary[F[String]]) extends FoldableSuite[F](name) { + def range(start: Long, endInclusive: Long): F[Long] test(s"Reducible[$name].reduceLeftM stack safety") {