Skip to content

Commit

Permalink
added a default id for Arrow (#2072)
Browse files Browse the repository at this point in the history
* added a default id for Arrow

we already have a law 
```
    F.lift(identity[A]) <-> F.id[A]
```
so it's hard to see why this shouldn't be given as a default.

* fix function

* fix Kleisli instance and Cokleisli instance

* added mima exception

* added more mima exception

* remove whitespace
  • Loading branch information
kailuowang authored Dec 6, 2017
1 parent 6a1207f commit 492fe75
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def mimaSettings(moduleName: String) = Seq(
exclude[DirectMissingMethodProblem]("cats.data.RWSTAlternative.traverse"),
exclude[DirectMissingMethodProblem]("cats.data.RWSTAlternative.sequence"),
exclude[ReversedMissingMethodProblem]("cats.MonadError.rethrow"),
exclude[ReversedMissingMethodProblem]("cats.syntax.MonadErrorSyntax.catsSyntaxMonadErrorRethrow")
exclude[ReversedMissingMethodProblem]("cats.syntax.MonadErrorSyntax.catsSyntaxMonadErrorRethrow"),
exclude[DirectMissingMethodProblem]("cats.data.CokleisliArrow.id"),
exclude[IncompatibleResultTypeProblem]("cats.data.CokleisliArrow.id")
)
}
)
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/arrow/Arrow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import simulacrum.typeclass
*/
def lift[A, B](f: A => B): F[A, B]

override def id[A]: F[A, A] = lift(identity)

override def dimap[A, B, C, D](fab: F[A, B])(f: C => A)(g: B => D): F[C, D] =
compose(lift(g), andThen(lift(f), fab))

Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/cats/data/Cokleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ private trait CokleisliArrow[F[_]] extends Arrow[Cokleisli[F, ?, ?]] with Coklei
def lift[A, B](f: A => B): Cokleisli[F, A, B] =
Cokleisli(fa => f(F.extract(fa)))

def id[A]: Cokleisli[F, A, A] =
Cokleisli(fa => F.extract(fa))

def first[A, B, C](fa: Cokleisli[F, A, B]): Cokleisli[F, (A, C), (B, C)] =
fa.first[C]

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private[data] trait KleisliChoice[F[_]] extends Choice[Kleisli[F, ?, ?]] with Kl
private[data] trait KleisliCategory[F[_]] extends Category[Kleisli[F, ?, ?]] with KleisliCompose[F] {
implicit def F: Monad[F]

def id[A]: Kleisli[F, A, A] = Kleisli.ask[F, A]
override def id[A]: Kleisli[F, A, A] = Kleisli.ask[F, A]
}

private[data] trait KleisliCompose[F[_]] extends Compose[Kleisli[F, ?, ?]] {
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala/cats/instances/function.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ private[instances] sealed trait Function1Instances extends Function1Instances0 {
case (a, c) => (fa(a), c)
}

def id[A]: A => A = a => a

override def split[A, B, C, D](f: A => B, g: C => D): ((A, C)) => (B, D) = {
case (a, c) => (f(a), g(c))
}
Expand Down

0 comments on commit 492fe75

Please sign in to comment.