Skip to content

Commit

Permalink
Add Bifoldable[Const]
Browse files Browse the repository at this point in the history
  • Loading branch information
adelbertc committed Feb 6, 2016
1 parent 720cc30 commit 547ee87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/src/main/scala/cats/data/Const.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ private[data] sealed abstract class ConstInstances extends ConstInstances0 {
def combine(x: Const[A, B], y: Const[A, B]): Const[A, B] =
x combine y
}

implicit val constBifoldable: Bifoldable[Const] =
new Bifoldable[Const] {
def bifoldLeft[A, B, C](fab: Const[A, B], c: C)(f: (C, A) => C, g: (C, B) => C): C =
f(c, fab.getConst)

def bifoldRight[A, B, C](fab: Const[A, B], c: Eval[C])(f: (A, Eval[C]) => Eval[C], g: (B, Eval[C]) => Eval[C]): Eval[C] =
f(fab.getConst, c)
}
}

private[data] sealed abstract class ConstInstances0 extends ConstInstances1 {
Expand Down
3 changes: 3 additions & 0 deletions tests/src/test/scala/cats/tests/ConstTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ConstTests extends CatsSuite {
checkAll("Const[String, Int]", ContravariantTests[Const[String, ?]].contravariant[Int, Int, Int])
checkAll("Contravariant[Const[String, ?]]", SerializableTests.serializable(Contravariant[Const[String, ?]]))

checkAll("Const[?, ?]", BifoldableTests[Const].bifoldable[Int, Int, Int])
checkAll("Bifoldable[Const]", SerializableTests.serializable(Bifoldable[Const]))

test("show") {

Const(1).show should === ("Const(1)")
Expand Down

0 comments on commit 547ee87

Please sign in to comment.