Skip to content

Commit

Permalink
Add Endo type alias for (A =>A) (#2076)
Browse files Browse the repository at this point in the history
* added reduceRightK and Endo

* added mima excpetion

* removed reduceRightK

* minor
  • Loading branch information
kailuowang authored Dec 10, 2017
1 parent b0cf5c0 commit 3e1a053
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/function.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/CategorySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/ComposeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion tests/src/test/scala/cats/tests/FoldableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 4 additions & 2 deletions tests/src/test/scala/cats/tests/ReducibleSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import org.scalacheck.Arbitrary

import cats.data.NonEmptyList

class ReducibleSuiteAdditional extends CatsSuite {
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit 3e1a053

Please sign in to comment.