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

Fix issue in Reducible #1685

Merged
merged 2 commits into from
May 26, 2017
Merged

Fix issue in Reducible #1685

merged 2 commits into from
May 26, 2017

Conversation

yilinwei
Copy link
Contributor

@yilinwei yilinwei commented May 19, 2017

courtesy of @ceedubs finding the bug.

@ceedubs
Copy link
Contributor

ceedubs commented May 19, 2017

👍 LGTM but maybe this is a sign that we should have a unit test for this :)

@yilinwei
Copy link
Contributor Author

@ceedubs point taken....

@codecov-io
Copy link

codecov-io commented May 19, 2017

Codecov Report

Merging #1685 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1685      +/-   ##
==========================================
+ Coverage   93.94%   93.96%   +0.01%     
==========================================
  Files         241      241              
  Lines        4096     4091       -5     
  Branches      156      151       -5     
==========================================
- Hits         3848     3844       -4     
+ Misses        248      247       -1
Impacted Files Coverage Δ
core/src/main/scala/cats/Reducible.scala 94.91% <100%> (+1.69%) ⬆️
core/src/main/scala/cats/Eval.scala 97.1% <0%> (-0.2%) ⬇️
core/src/main/scala/cats/data/EitherT.scala 96.52% <0%> (ø) ⬆️

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 cc4080c...bb9f8c9. Read the comment docs.

@kailuowang
Copy link
Contributor

I think in principle every method that is not a simple delegation should be covered. This chrome extension is really helpful in checking that.

@peterneyens
Copy link
Collaborator

peterneyens commented May 19, 2017

I think the problem here is that all the instances of Reducible override get. Another method I can think of with the same issue is Foldable#toList / Reducible#toNonEmptyList.

It would be nice if we could somehow check the consistency (#1684) and benchmark (something we talked about in #1532, see #1532 (comment)) overridden and the default implementation of type class methods.

@kailuowang
Copy link
Contributor

How about we add a doctest to cover this and address the overrides test coverage in #1684? That way we can merge this fix sooner.

@peterneyens
Copy link
Collaborator

@kailuowang, do you mean something like :

scala> import cats.data.NonEmptyList
scala> import cats.implicits._

scala> val R = new NonEmptyReducible[NonEmptyList, List] {
     |   def split[A](nel: NonEmptyList[A]): (A, List[A]) = (nel.head, nel.tail)
     | }

scala> val nel = NonEmptyList.of(1,2,3)

scala> R.get(nel, 1L)
res0: Option[Int] = Some(2)

scala> R.get(nel, 4L)
res1: Option[Int] = None

@kailuowang
Copy link
Contributor

@peterneyens yup. that would work.

@@ -227,7 +227,7 @@ abstract class NonEmptyReducible[F[_], G[_]](implicit G: Foldable[G]) extends Re
}

override def get[A](fa: F[A])(idx: Long): Option[A] =
if (idx == 0L) Some(split(fa)._1) else G.get(split(fa)._2)(idx)
if (idx == 0L) Some(split(fa)._1) else G.get(split(fa)._2)(idx - 1L)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not actually tested according to codecov.

Can we write a test to explicitly exercise this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johnynek done.

@yilinwei
Copy link
Contributor Author

Failure in the test is due to the Kleisli Eq presumably not working as intended; given that this PR doesn't touch that are we good to merge?

@djspiewak djspiewak added this to the 1.0.0-MF milestone May 26, 2017
@djspiewak
Copy link
Member

Merging with two sign-offs.

@djspiewak djspiewak merged commit bb9f8c9 into typelevel:master May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants