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

Follow up to #3233 #3237

Merged
merged 3 commits into from
Jan 4, 2020
Merged

Follow up to #3233 #3237

merged 3 commits into from
Jan 4, 2020

Conversation

strong-zero
Copy link
Contributor

A follow up to #3233 based on the helpful comments by @fthomas and @rossabaker: OptionT.{whenF, unlessF} should return OptionT.none when the given condition is false.

@codecov-io
Copy link

codecov-io commented Jan 4, 2020

Codecov Report

Merging #3237 into master will decrease coverage by 0.33%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3237      +/-   ##
==========================================
- Coverage   93.38%   93.05%   -0.34%     
==========================================
  Files         372      376       +4     
  Lines        7226     7413     +187     
  Branches      185      201      +16     
==========================================
+ Hits         6748     6898     +150     
- Misses        478      515      +37
Flag Coverage Δ
#scala_version_212 93.38% <100%> (ø) ⬆️
#scala_version_213 92.82% <100%> (?)
Impacted Files Coverage Δ
core/src/main/scala/cats/data/OptionT.scala 95.9% <100%> (ø) ⬆️
...e/src/main/scala-2.13+/cats/data/ZipLazyList.scala 77.77% <0%> (ø)
...src/main/scala-2.13+/cats/instances/lazyList.scala 100% <0%> (ø)
....13+/cats/kernel/instances/LazyListInstances.scala 100% <0%> (ø)
.../main/scala-2.13+/cats/data/NonEmptyLazyList.scala 62.5% <0%> (ø)
...in/scala/cats/data/AbstractNonEmptyInstances.scala 100% <0%> (+3.44%) ⬆️

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 534d392...abd798b. Read the comment docs.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

Thank you for persevering on this!

}

forAll { (i: List[Int], b: Boolean) =>
OptionT.whenF[List, Int](b)(i).value should ===(when(b, i).sequence)
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure whether I'd ever reason about code by this property, but I noticed it when I thought about the types and it seems to pass. I'm curious whether others think this one is actually useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test case is very interesting to me, but certainly less obvious that it universally holds (not only in the case when F = List).

Added abd798b to remove it for now.
👍 to restore it if someone knows a good explanation about it.

forAll { (li: List[Int], b: Boolean) =>
OptionT.whenF(b)(li).value should ===(li.map(when(b, _)))
test("OptionT.whenF[F, A] consistent with Option.when") {
def when[A]: (Boolean, A) => Option[A] = (c: Boolean, a: A) => if (c) Some(a) else None
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but since the property refers to Option.when, it might be helpful to future readers to comment why it's inlined here (e.g., that it's not available before 2.13).

Copy link
Member

@fthomas fthomas left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @strong-zero!

@rossabaker rossabaker merged commit f839716 into typelevel:master Jan 4, 2020
@strong-zero strong-zero deleted the follow-up-to-3233 branch January 5, 2020 00:01
@travisbrown travisbrown added this to the 2.2.0-M1 milestone Jan 14, 2020
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.

5 participants