-
-
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 groupBy for NonEmptySet #2285
Conversation
* Groups elements inside this `NonEmptySet` according to the `Order` | ||
* of the keys produced by the given mapping function. | ||
*/ | ||
def groupBy[B](f: A => B)(implicit B: Order[B]): NonEmptyMap[B, NonEmptySet[A]] = { |
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.
If we're returning NonEmptyMap
here, does it make sense to make NonEmptyList#groupBy
also return a non-empty map? @LukaJCB
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.
Yeah that's probably true, but we can't change it without breaking compatibility
Right. I'm sooo excited for the 2.x branch ;)
…On Sat, Jun 9, 2018, 12:52 Luka Jacobowitz ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In core/src/main/scala/cats/data/NonEmptySet.scala
<#2285 (comment)>:
> @@ -346,6 +346,21 @@ sealed class NonEmptySetOps[A](val value: NonEmptySet[A]) {
*/
def zipWithIndex: NonEmptySet[(A, Int)] =
NonEmptySetImpl.create(toSortedSet.zipWithIndex)
+
+ /**
+ * Groups elements inside this `NonEmptySet` according to the `Order`
+ * of the keys produced by the given mapping function.
+ */
+ def groupBy[B](f: A => B)(implicit B: Order[B]): NonEmptyMap[B, NonEmptySet[A]] = {
Yeah that's probably true, but we can't change it without breaking
compatibility
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2285 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA2npN2WR_5nkVpLBKPbM2gawFhS6yrZks5t67bygaJpZM4UhTAQ>
.
|
Codecov Report
@@ Coverage Diff @@
## master #2285 +/- ##
==========================================
+ Coverage 95.03% 95.05% +0.02%
==========================================
Files 337 338 +1
Lines 5840 5850 +10
Branches 222 220 -2
==========================================
+ Hits 5550 5561 +11
+ Misses 290 289 -1
Continue to review full report at Codecov.
|
to make this available with |
Sorry I missed that. |
What we did forget is to add a specific import for these syntax extensions, we should add an |
@LukaJCB any test that we can have for this? |
@Obarros I think there is a spec that checks if syntax compiles. Look for I think the list syntax isn't there, so we could add that now that we're at it |
2ac680e
to
7ce57d8
Compare
looks good, |
val grouped: SortedMap[B, NonEmptySet[A]] = set.groupByNes(f) | ||
} | ||
|
||
def testNonEmptyList[A: Order, B: Order] : Unit = { |
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 don't need this Order
constraint on A
, leaving it on B
should be enough. :)
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.
Thanks, @LukaJCB.
Let me remove it, I will also rebase on top of the latest master before squashing the commits and push.
@Obarros, it's no big deal but it's not necessary to squash before merge. We usually do squash merge (meaning all commits on pr will be squashed on merge by GitHub) . Having separate commits helps reviewing the latest changes. |
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.
Thanks again @Obarros! Merging.
Should fixe #2282.
@LukaJCB PTAL.