Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Traverse[Id] and Id law-checking #639

Merged
merged 1 commit into from
Nov 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ package object cats {
* encodes pure unary function application.
*/
type Id[A] = A
implicit val Id: Bimonad[Id] =
new Bimonad[Id] {
implicit val Id: Bimonad[Id] with Traverse[Id] =
new Bimonad[Id] with Traverse[Id] {
def pure[A](a: A): A = a
def extract[A](a: A): A = a
def flatMap[A, B](a: A)(f: A => B): B = f(a)
Expand All @@ -38,6 +38,11 @@ package object cats {
override def map2[A, B, Z](fa: A, fb: B)(f: (A, B) => Z): Z = f(fa, fb)
override def lift[A, B](f: A => B): A => B = f
override def imap[A, B](fa: A)(f: A => B)(fi: B => A): B = f(fa)
def foldLeft[A, B](a: A, b: B)(f: (B, A) => B) = f(b, a)
def foldRight[A, B](a: A, lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] =
f(a, lb)
def traverse[G[_], A, B](a: A)(f: A => G[B])(implicit G: Applicative[G]): G[B] =
f(a)
}

type Eq[A] = algebra.Eq[A]
Expand Down
13 changes: 13 additions & 0 deletions tests/src/test/scala/cats/tests/IdTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cats
package tests

import org.scalacheck.Prop.forAll
import cats.laws.discipline._

class IdTests extends CatsSuite {
checkAll("Id[Int]", BimonadTests[Id].bimonad[Int, Int, Int])
checkAll("Bimonad[Id]", SerializableTests.serializable(Bimonad[Id]))

checkAll("Id[Int]", TraverseTests[Id].traverse[Int, Int, Int, Int, Option, Option])
checkAll("Traverse[Id]", SerializableTests.serializable(Traverse[Id]))
}