Clean up some NonEmpty stuff#3307
Merged
Merged
Conversation
Contributor
|
Thanks! My sentiment towards these classes has always been slightly 👎 in having them in The more unified API introduced in this PR is nice and I agree that the long term plan should be moving them to their own module. Speaking of which, we might need to start thinking about which |
LukaJCB
approved these changes
Feb 20, 2020
kailuowang
approved these changes
Feb 20, 2020
Contributor
Author
|
Thanks all! I'm going to merge this without squashing since the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unfortunately
cats.datais kind of a disaster, in part because all of theNonEmptyXtypes are unrelated and don't implement any particular interface. This means that not only do we have four different ways to encode non-empty collections, each of our implementations has a fairly arbitrary grab-bag of methods attached to it.This PR adds several "missing" methods:
Chain:sortBy,sorted,zipWithIndex.NonEmptyChain:sortBy,sorted,zipWithIndex,groupByNem,toNem,toNes,show.NonEmptyLazyList:sortBy,sorted,groupBy,groupByNem,toNem,toNes,show.NonEmptyList:iterator.NonEmptyVector:iterator,groupBy,groupByNem,toNem,toNes.This PR also introduces a new
NonEmptyCollectioninterface that is implemented byNonEmptyChain,NonEmptyLazyList,NonEmptyList, andNonEmptyVector. It's roughly a union of the methods of these types, and the additions above were what was necessary to fill out these implementations. It's implemented as a universal trait, and does not interfere with value classes.It's worth noting that
NonEmptyCollectionis not part of the public Cats API. The goal is to help us maintain consistency (and as a side effect to make testing easier), not to provide a user-facing abstraction. The user only sees a more consistent set of methods across these types.I've also fixed one misnamed method on
NonEmptyLazyList:collectLazyList(now deprecated) is clearly a typo forcollectFirst.It's worth noting that some methods that should be on
NonEmptyCollectioncan't be, because of mistakes that we've made in the past. For example,NonEmptyChainhas agroupBythat returns aNonEmptyMap, while the otherNonEmptyXcollections call that methodgroupByNemand havegroupByreturn aSortedSet. AlsoChainhaslengthandsizemethods that return aLong(?), whileNonEmptyChainhas aLong-returninglength, but nosize(??), while the otherNonEmptyXcollections have alengththat returns anInt(and some of them have asize: Int). I can't wait forcats.datato be banished to its own module in Cats 3.