Skip to content

Commit

Permalink
addressed review feedback, moved implicits to the top of the hierarch…
Browse files Browse the repository at this point in the history
…y (available to all)
  • Loading branch information
gagandeepkalra committed Jun 3, 2020
1 parent cfb8ead commit 6af528d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 40 deletions.
3 changes: 0 additions & 3 deletions core/src/main/scala/cats/arrow/Arrow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ import scala.annotation.implicitNotFound

object Arrow {

implicit val partialFunction: Arrow[PartialFunction] =
cats.instances.partialFunction.catsStdInstancesForArrowHierarchy

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/cats/arrow/ArrowChoice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ import scala.annotation.implicitNotFound

object ArrowChoice {

implicit val partialFunction: ArrowChoice[PartialFunction] =
cats.instances.partialFunction.catsStdInstancesForArrowHierarchy

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/cats/arrow/Choice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ import scala.annotation.implicitNotFound

object Choice {

implicit val partialFunction: Choice[PartialFunction] =
cats.instances.partialFunction.catsStdInstancesForArrowHierarchy

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/cats/arrow/CommutativeArrow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import scala.annotation.implicitNotFound

object CommutativeArrow {

implicit val partialFunction: CommutativeArrow[PartialFunction] =
cats.instances.partialFunction.catsStdInstancesForArrowHierarchy

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/scala/cats/arrow/Compose.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ import scala.annotation.implicitNotFound
}

object Compose {
implicit def catsInstancesForFunction1: ArrowChoice[Function1] with CommutativeArrow[Function1] =
implicit val catsInstancesForFunction1: ArrowChoice[Function1] with CommutativeArrow[Function1] =
cats.instances.function.catsStdInstancesForFunction1
implicit def catsComposeForMap: Compose[Map] = cats.instances.map.catsStdComposeForMap
implicit val catsComposeForMap: Compose[Map] = cats.instances.map.catsStdComposeForMap

implicit val catsInstancesForPartialFunction: ArrowChoice[PartialFunction] with CommutativeArrow[PartialFunction] =
cats.instances.partialFunction.catsStdInstancesForPartialFunction

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/cats/arrow/Profunctor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ import scala.annotation.implicitNotFound
}

object Profunctor {
implicit def catsStrongForFunction1: Strong[Function1] =
implicit val catsStrongForFunction1: Strong[Function1] =
cats.instances.function.catsStdInstancesForFunction1

implicit val catsStrongForPartialFunction: Strong[PartialFunction] =
cats.instances.partialFunction.catsStdInstancesForPartialFunction

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/cats/instances/partialFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cats.arrow.{ArrowChoice, CommutativeArrow}

trait PartialFunctionInstances {

implicit val catsStdInstancesForArrowHierarchy: ArrowChoice[PartialFunction] with CommutativeArrow[PartialFunction] =
implicit val catsStdInstancesForPartialFunction: ArrowChoice[PartialFunction] with CommutativeArrow[PartialFunction] =
new ArrowChoice[PartialFunction] with CommutativeArrow[PartialFunction] {

/**
Expand All @@ -19,14 +19,14 @@ trait PartialFunctionInstances {
* res1: Either[Long,Double] = Right(3.0)
* }}}
*/
override def choose[A, B, C, D](f: PartialFunction[A, C])(
g: PartialFunction[B, D]
): PartialFunction[Either[A, B], Either[C, D]] = {
override def choose[A, B, C, D](
f: PartialFunction[A, C]
)(g: PartialFunction[B, D]): PartialFunction[Either[A, B], Either[C, D]] = {
case Left(a) if f.isDefinedAt(a) => Left(f(a))
case Right(b) if g.isDefinedAt(b) => Right(g(b))
}

override def lift[A, B](f: A => B): PartialFunction[A, B] = { case a if a.isInstanceOf[A] => f(a) }
override def lift[A, B](f: A => B): PartialFunction[A, B] = { case a => f(a) }

/**
* Create a new `F` that takes two inputs, but only modifies the first input
Expand Down
6 changes: 4 additions & 2 deletions kernel/src/main/scala/cats/kernel/Eq.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cats.kernel

import java.util.UUID

import cats.kernel.compat.scalaVersionSpecific._

import scala.collection.immutable.{BitSet, Queue, SortedMap, SortedSet}
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.math.Equiv
import scala.{specialized => sp}
import scala.util.{Failure, Success, Try}
import compat.scalaVersionSpecific._
import scala.{specialized => sp}

/**
* A type class used to determine equality between 2 instances of the same
Expand Down
12 changes: 4 additions & 8 deletions laws/src/main/scala/cats/laws/discipline/Eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package cats
package laws
package discipline

import cats.data.RepresentableStore
import cats.Eq
import cats.data.AndThen
import cats.data.{AndThen, RepresentableStore}
import cats.instances.boolean._
import cats.instances.int._
import cats.instances.string._
import cats.instances.tuple._
import cats.kernel._
import cats.platform.Platform
import cats.syntax.eq._
Expand All @@ -22,12 +19,11 @@ object eq {
implicit def catsLawsEqForFn2[A, B, C](implicit ev: Eq[((A, B)) => C]): Eq[(A, B) => C] =
Eq.by((_: (A, B) => C).tupled)

implicit def catsLawsEqForPartialFunctionExhaustive[A, B](implicit A: ExhaustiveCheck[A],
B: Eq[B]): Eq[PartialFunction[A, B]] =
implicit def catsLawsEqForPartialFunctionExhaustive[A: ExhaustiveCheck, B: Eq]: Eq[PartialFunction[A, B]] =
Eq.instance((f, g) =>
A.allValues
ExhaustiveCheck[A].allValues
.filter(a => f.isDefinedAt(a) || g.isDefinedAt(a))
.forall(a => f.isDefinedAt(a) && g.isDefinedAt(a) && B.eqv(f(a), g(a)))
.forall(a => f.isDefinedAt(a) && g.isDefinedAt(a) && Eq[B].eqv(f(a), g(a)))
)

implicit def catsLawsEqForAndThen[A, B](implicit eqAB: Eq[A => B]): Eq[AndThen[A, B]] =
Expand Down
20 changes: 10 additions & 10 deletions tests/src/test/scala/cats/tests/PartialFunctionSuite.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package cats.tests
import cats.arrow.{ArrowChoice, Choice, CommutativeArrow}
import cats.arrow.{ArrowChoice, CommutativeArrow}
import cats.kernel.laws.discipline.SerializableTests
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._
import cats.laws.discipline.{ArrowChoiceTests, ChoiceTests, CommutativeArrowTests, MiniInt}
import cats.laws.discipline.{ArrowChoiceTests, CommutativeArrowTests, MiniInt}

class PartialFunctionSuite extends CatsSuite {

checkAll("ArrowChoice[PartialFunction]", SerializableTests.serializable(ArrowChoice[PartialFunction]))

checkAll("PartialFunction",
ArrowChoiceTests[PartialFunction].arrowChoice[MiniInt, MiniInt, MiniInt, MiniInt, MiniInt, MiniInt]
)

checkAll("CommutativeArrow[PartialFunction]", SerializableTests.serializable(CommutativeArrow[PartialFunction]))
checkAll(
"PartialFunction",
CommutativeArrowTests[PartialFunction].commutativeArrow[MiniInt, MiniInt, MiniInt, MiniInt, MiniInt, MiniInt]
)
checkAll("Arrow[PartialFunction]", SerializableTests.serializable(CommutativeArrow[PartialFunction]))

checkAll("PartialFunction", ChoiceTests[PartialFunction].choice[MiniInt, Boolean, Int, Long])
checkAll("Choice[PartialFunction]", SerializableTests.serializable(Choice[PartialFunction]))

checkAll("PartialFunction",
ArrowChoiceTests[PartialFunction].arrowChoice[MiniInt, MiniInt, MiniInt, MiniInt, MiniInt, MiniInt])
checkAll("ArrowChoice[PartialFunction]", SerializableTests.serializable(ArrowChoice[PartialFunction]))

}

0 comments on commit 6af528d

Please sign in to comment.