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

Clean Up Predicate A Bit #269

Merged
merged 3 commits into from
Feb 14, 2020
Merged

Clean Up Predicate A Bit #269

merged 3 commits into from
Feb 14, 2020

Conversation

stephen-lazaro
Copy link
Contributor

Alias existing functions from symbolic ones
Add contravariant instance
Guarantee all instances serializable

For #202.

Alias existing functions from symbolic ones
Add contravariant instance
Guarantee all instances serializable
implicit def predicateMonoid[A]: Monoid[Predicate[A]] = new Monoid[Predicate[A]] {
override def empty: Predicate[A] = Predicate.empty
override def combine(l: Predicate[A], r: Predicate[A]): Predicate[A] = l union r
}

implicit val predicateInstance: MonoidK[Predicate] = new MonoidK[Predicate] {
implicit val predicateMonoidK: MonoidK[Predicate] = new MonoidK[Predicate] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno if this rename is cool from a bincompat perspective.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are no guarantees about that yet, so it's fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add mima checking sooner than later.

I personally really avoid libraries that don't try to minimize breaks (and in fact, despite contributing to this library, I am afraid to depend on it).

Copy link
Contributor

Choose a reason for hiding this comment

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

Happy to call it 1.0 at some point in the near future.

@codecov-io
Copy link

codecov-io commented Jan 16, 2020

Codecov Report

Merging #269 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #269      +/-   ##
=========================================
+ Coverage   91.19%   91.5%   +0.31%     
=========================================
  Files          25      24       -1     
  Lines        1612    1625      +13     
  Branches      337     214     -123     
=========================================
+ Hits         1470    1487      +17     
+ Misses        142     138       -4
Impacted Files Coverage Δ
...re/src/main/scala/cats/collections/Predicate.scala 77.27% <100%> (+16.16%) ⬆️
core/src/main/scala/cats/collections/Set.scala 88.69% <0%> (-0.87%) ⬇️
core/src/main/scala/cats/collections/Dequeue.scala 56.63% <0%> (-0.39%) ⬇️
.../src/main/scala/cats/collections/PairingHeap.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/collections/BitSet.scala 97.36% <0%> (ø) ⬆️
...ons/laws/discipline/PartiallyOrderedSetTests.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/collections/Range.scala 100% <0%> (ø) ⬆️
...12-/cats/collections/compat/BitSetWrapperSet.scala
core/src/main/scala/cats/collections/Heap.scala 98.56% <0%> (+0.02%) ⬆️
...ats/collections/laws/PartiallyOrderedSetLaws.scala 91.42% <0%> (+0.25%) ⬆️
... and 4 more

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 e8eb439...d2de430. Read the comment docs.

override def contramap[A, B](fb: Predicate[A])(f: B => A): Predicate[B] =
Predicate(f andThen fb.apply)
override def product[A, B](fa: Predicate[A], fb: Predicate[B]): Predicate[(A, B)] =
Predicate(v => fa(v._1) || fb(v._2))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about the choice of || here, what's the reasoning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's definitely a bit arbitrary, but I made the choice based on having the monoidal product act similarly to the monoids already defined for this type. || gives us union, which is probably the more in line with user expectations given the monoids are also union.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add law tests for ContravariantMonoidal? Then I think we're good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll get to that today / tomorrow probably.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it with kind of stupid Eq instances, but I'm not sure there are better ones. If there's a standard way to do Eq for functions, let me know and I can change it up.

@larsrh larsrh requested a review from johnynek February 2, 2020 10:39
@larsrh
Copy link
Contributor

larsrh commented Feb 14, 2020

Thanks @stephen-lazaro!

@larsrh larsrh merged commit e1b06cc into typelevel:master Feb 14, 2020
@stephen-lazaro stephen-lazaro deleted the patch-1 branch February 14, 2020 18:09
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.

4 participants