Skip to content

Commit

Permalink
Merge pull request #1130 from hamishdickson/add-monoid-syntax
Browse files Browse the repository at this point in the history
Add monoid syntax
  • Loading branch information
ceedubs authored Jun 16, 2016
2 parents 1323d57 + 6ad6b72 commit 400c24d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ trait AllSyntax
with MonadCombineSyntax
with MonadErrorSyntax
with MonadFilterSyntax
with MonoidSyntax
with OptionSyntax
with OrderSyntax
with PartialOrderSyntax
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/scala/cats/syntax/monoid.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cats
package syntax

trait MonoidSyntax extends SemigroupSyntax {
// TODO: use simulacrum instances eventually
implicit def catsSyntaxMonoid[A: Monoid](a: A): MonoidOps[A] =
new MonoidOps[A](a)
}

final class MonoidOps[A: Monoid](lhs: A) {
def isEmpty(implicit eq: Eq[A]): Boolean = Monoid[A].isEmpty(lhs)(eq)
}
6 changes: 6 additions & 0 deletions tests/src/test/scala/cats/tests/SyntaxTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class SyntaxTests extends AllInstances with AllSyntax {
val z: A = x |-| y
}

def testMonoid[A: Monoid]: Unit = {
val x = mock[A]
implicit val y = mock[Eq[A]]
val z: Boolean = x.isEmpty
}

def testEq[A: Eq]: Unit = {
val x = mock[A]
val y = mock[A]
Expand Down

0 comments on commit 400c24d

Please sign in to comment.