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

Adds Semigroup for Const #718

Merged
merged 1 commit into from
Dec 6, 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
5 changes: 5 additions & 0 deletions core/src/main/scala/cats/data/Const.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ private[data] sealed abstract class ConstInstances extends ConstInstances0 {
}

private[data] sealed abstract class ConstInstances0 extends ConstInstances1 {

implicit def constSemigroup[A: Semigroup, B]: Semigroup[Const[A, B]] = new Semigroup[Const[A, B]] {
def combine(x: Const[A, B], y: Const[A, B]): Const[A, B] = x combine y
}

implicit def constPartialOrder[A: PartialOrder, B]: PartialOrder[Const[A, B]] = new PartialOrder[Const[A, B]]{
def partialCompare(x: Const[A, B], y: Const[A, B]): Double =
x partialCompare y
Expand Down
2 changes: 2 additions & 0 deletions tests/src/test/scala/cats/tests/ConstTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ConstTests extends CatsSuite {
// Algebra checks for Serializability of instances as part of the laws
checkAll("Monoid[Const[Int, String]]", GroupLaws[Const[Int, String]].monoid)

checkAll("Const[NonEmptyList[Int], String]", GroupLaws[Const[NonEmptyList[Int], String]].semigroup)

// Note while Eq is a superclass of PartialOrder and PartialOrder a superclass
// of Order, you can get different instances with different (more general) constraints.
// For instance, you can get an Order for Const if the first type parameter has an Order,
Expand Down