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

Add empty to State and StateT objects #2533

Merged
merged 1 commit into from
Oct 1, 2018
Merged

Add empty to State and StateT objects #2533

merged 1 commit into from
Oct 1, 2018

Conversation

larsrh
Copy link
Contributor

@larsrh larsrh commented Sep 25, 2018

Work by @sderosiaux in #2294. Rebased to current master. For some reason, the bincompat error also went away (at least locally).

@LukaJCB
Copy link
Member

LukaJCB commented Sep 25, 2018

Seems like there's still a bincompat issue for 2.11

@larsrh
Copy link
Contributor Author

larsrh commented Sep 26, 2018

Ah, right. 2.11 doesn't like methods added to traits. But this should be fine with an exception, no?

@LukaJCB
Copy link
Member

LukaJCB commented Sep 26, 2018

We can add new methods by creating a new trait and mixing it in, similar to what we've been doing with the syntax additions :)

@larsrh
Copy link
Contributor Author

larsrh commented Sep 26, 2018

Smart. I've updated the commit accordingly.

@codecov-io
Copy link

codecov-io commented Sep 26, 2018

Codecov Report

Merging #2533 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2533      +/-   ##
==========================================
+ Coverage   95.17%   95.17%   +<.01%     
==========================================
  Files         359      359              
  Lines        6553     6555       +2     
  Branches      278      286       +8     
==========================================
+ Hits         6237     6239       +2     
  Misses        316      316
Impacted Files Coverage Δ
core/src/main/scala/cats/data/package.scala 88.88% <ø> (ø) ⬆️
core/src/main/scala/cats/data/IndexedStateT.scala 89.69% <100%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15f4e59...123af78. Read the comment docs.

@larsrh
Copy link
Contributor Author

larsrh commented Sep 26, 2018

And we're green!

LukaJCB
LukaJCB previously approved these changes Sep 26, 2018
@@ -223,6 +223,11 @@ object IndexedStateT extends IndexedStateTInstances with CommonStateTConstructor
IndexedStateT(_ => F.map(fsb)(s => (s, ())))
}

private[data] trait CommonStateTConstructors0 extends CommonStateTConstructors {
def empty[F[_], S, A: Monoid](implicit F: Applicative[F]): IndexedStateT[F, S, S, A] =
pure(Monoid[A].empty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use : Monoid for A but not use : Applicative for F? I'd be inclined to not use the syntactic sugar for either so you can avoid do something like F.pure(A.empty) and avoid an extra Monoid.apply[A] call.

@larsrh
Copy link
Contributor Author

larsrh commented Sep 30, 2018

@ceedubs Is this fine with you now?

Copy link
Contributor

@ceedubs ceedubs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsrh I think that it's probably good, but I left a couple of questions. Let me know what you think. I'm okay with approving in its current form.

@@ -223,6 +223,11 @@ object IndexedStateT extends IndexedStateTInstances with CommonStateTConstructor
IndexedStateT(_ => F.map(fsb)(s => (s, ())))
}

private[data] trait CommonStateTConstructors0 extends CommonStateTConstructors {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason to introduce this new trait as opposed to just putting this method directly into the object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary compatibility: #2533 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be precise, the function is not only provided on the IndexedStateT object, but also on StateT. This is the reason why it has to go into a trait in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay that makes sense. Thanks for the explanation.

core/src/main/scala/cats/data/IndexedStateT.scala Outdated Show resolved Hide resolved
@larsrh
Copy link
Contributor Author

larsrh commented Sep 30, 2018

@ceedubs Updated accordingly.

Copy link
Contributor

@ceedubs ceedubs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @larsrh!

@LukaJCB LukaJCB merged commit 2976807 into typelevel:master Oct 1, 2018
@larsrh larsrh deleted the topic/pr-2294-redux branch October 1, 2018 20:55
@kailuowang kailuowang added this to the 1.5 milestone Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants