Skip to content

Commit

Permalink
Merge pull request #4036 from BalmungSan/patch-1
Browse files Browse the repository at this point in the history
Adding Id.apply
  • Loading branch information
rossabaker authored Nov 6, 2021
2 parents 1a7b9d8 + 7270f8f commit 6a6d4e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ package object cats {
* encodes pure unary function application.
*/
type Id[A] = A
object Id {
def apply[A](a: A): Id[A] = a
}

type Endo[A] = A => A

val catsInstancesForId: Bimonad[Id] with CommutativeMonad[Id] with NonEmptyTraverse[Id] with Distributive[Id] =
Expand Down
12 changes: 12 additions & 0 deletions tests/src/test/scala/cats/tests/IdSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package cats.tests

import cats.{Bimonad, CommutativeMonad, Id, Reducible, Traverse}
import cats.laws.discipline._
import cats.syntax.applicative._
import cats.syntax.eq._
import org.scalacheck.Prop._

class IdSuite extends CatsSuite {
implicit val iso: SemigroupalTests.Isomorphisms[Id] =
Expand All @@ -18,4 +21,13 @@ class IdSuite extends CatsSuite {

checkAll("Id[Int]", ReducibleTests[Id].reducible[Option, Int, Int])
checkAll("Reducible[Id]", SerializableTests.serializable(Reducible[Id]))

test("Id#apply") {
forAll { (i: Int) =>
val id = Id(i)
assert(id === (i: Id[Int]))
assert(id === i.pure[Id])
assert(id === i)
}
}
}

0 comments on commit 6a6d4e4

Please sign in to comment.