-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 SemigroupK instance for Xor + tests #996
Changes from 3 commits
63d186b
e66d238
0bae0ca
8636343
db83772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package tests | |
|
||
import cats.data.{NonEmptyList, Xor, XorT} | ||
import cats.data.Xor._ | ||
import cats.laws.discipline.{SemigroupKTests} | ||
import cats.laws.discipline.arbitrary._ | ||
import cats.laws.discipline.{BitraverseTests, TraverseTests, MonadErrorTests, SerializableTests, CartesianTests} | ||
import cats.laws.discipline.eq.tuple3Eq | ||
|
@@ -46,6 +47,12 @@ class XorTests extends CatsSuite { | |
checkAll("Eq[ListWrapper[String] Xor ListWrapper[Int]]", SerializableTests.serializable(Eq[ListWrapper[String] Xor ListWrapper[Int]])) | ||
} | ||
|
||
{ | ||
implicit val L = ListWrapper.semigroup[String] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is creating a local (to the surrounding In this case, the I'd imagine all of these locally-scoped instances are somewhat terrifying for someone who is used to Haskell :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, good call. this is what I get for submitting a PR at 8am before breakfast :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and, yeah, coming from Haskell it feels like these instances are just flying around and I have no idea what's happening :) For example, I didn't know you could introduce a local instance by wrapping something in curly braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the implicit scope rules are incredibly complicated (which admittedly we use as a "feature" quite a bit in cats to aid in implicit resolution). In this case we are using the curly braces to have it scoped locally to that block instead of to the whole class/object. 😈 |
||
checkAll("Xor[ListWrapper[String], ?]", SemigroupKTests[Xor[ListWrapper[String], ?]].semigroupK[Int]) | ||
checkAll("SemigroupK[Xor[ListWrapper[String], ?]]", SerializableTests.serializable(SemigroupK[Xor[ListWrapper[String], ?]])) | ||
} | ||
|
||
implicit val arbitraryXor: Arbitrary[Xor[Int, String]] = Arbitrary { | ||
for { | ||
left <- arbitrary[Boolean] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is minor, but now that the
SemigroupK
instance no longer requires aSemigroup[L]
, theSemigroupK
tests down at line ~49 don't need the localSemigroup[ListWrapper[String]]
instance and could be moved up here, similarly to this comment.