-
-
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 some more OptionT instances. #1103
Conversation
Current coverage is 88.78%
@@ master #1103 diff @@
==========================================
Files 227 227
Lines 2946 2968 +22
Methods 2890 2910 +20
Messages 0 0
Branches 53 56 +3
==========================================
+ Hits 2611 2635 +24
+ Misses 335 333 -2
Partials 0 0
|
7ba501a
to
67c7f39
Compare
|
||
implicit val monadError = OptionT.catsDataMonadErrorForOptionT[SXor, String] | ||
|
||
// checkAll("OptionT[String Xor ?, Int]", MonadErrorTests[OptionT[SXor, ?], String].monadError[Int, Int, Int]) |
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.
I need an Arbitrary[λ[(α, β) => OptionT[String Xor α, β]]]
which I don't seem to get from the Arbitrary
instances of Xor
and OptionT
.
I need to figure how to create this instance and if it has a place in laws.discipline.arbitrary
.
The only instances currently still missing which can added for I'm currently failing to provide an I am also not sure why the |
26a99a9
to
bf91788
Compare
|
||
implicit val iso = CartesianTests.Isomorphisms.invariant[OptionT[SXor, ?]] | ||
|
||
checkAll("OptionT[String Xor ?, Int]", MonadErrorTests[OptionT[SXor, ?], String].monadError[Int, Int, Int]) |
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.
MonadErrorTests
is working now, but I had to supply all the Arbitrary
and Eq
instances myself, I don't know if there is a better way ?
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.
The better way is probably #1073 but let's hold off on that for this PR.
bf91788
to
66332e5
Compare
Added `Eq`, `PartialOrder`, `Order`. Added `Semigroup`, `Monoid` Added `SemigroupK`, `MonoidK` Added `Foldable`, `Traverse` Added `MonadError`, `MonadCombine` and `MonadFilter` (the last two instances are dissabled, because they violate the same laws as the equivalent XorT instances). Rewrote the tests to use `ListWrapper`. I used the ListWrapper methods added by @yilinwei in # 1106.
66332e5
to
bbd3e12
Compare
/* TODO violates right absorbtion, right distributivity, and left distributivity -- re-enable when MonadCombine laws are split in to weak/strong | ||
implicit def catsDataMonadCombineForOptionT[F[_]](implicit F0: Monad[F]): MonadCombine[OptionT[F, ?]] = | ||
new OptionTMonadCombine[F] { implicit val F = F0 } | ||
*/ |
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.
I think we should probably track this (and the other below) with a GitHub issue instead of commented-out code.
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.
I followed the example of XorT
to include them disabled.
Do I drop the implicit functions, the traits OptionTMonadFilter
and OptionTMonadCombine
and their tests ?
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.
@peterneyens that's what I'd be inclined to do. We always have git history if people want to pull them back out (and ideally the GitHub issue tracking this could link to the previous implementation).
Thanks a bunch @peterneyens, this is great! I left a minor comment about commented-out code, but other than that 👍. |
01d8fd0
to
c20a25b
Compare
Clean up the test of Monoid and Semigroup.
c20a25b
to
c3cae9e
Compare
|
@xuwei-k Thanks for pointing this out, I already found it kind of strange that this didn't give any problems and didn't really think this through. |
implicit def catsDataMonadErrorForOptionT[F[_], E](implicit F0: MonadError[F, E]): MonadError[OptionT[F, ?], E] = | ||
new OptionTMonadError[F, E] { implicit val F = F0 } | ||
|
||
implicit def catsDataSemigroupK[F[_]](implicit F0: Monad[F]): SemigroupK[OptionT[F, ?]] = |
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.
I think you want a forOptionT
at the end of this name.
One more minor comment, then I think this is good to go! |
Add a "test" to check the implicit resolution of OptionT instances.
1dffb84
to
2183b75
Compare
👍 |
This is awesome. LGTM 👍 |
Eq
,PartialOrder
andOrder
.Semigroup
andMonoid
.SemigroupK
andMonoidK
MonadError
,MonadCombine
andMonadFilter
(the last twoinstances are dissabled, because they violate the same laws as the
equivalent
Xor
T instances).