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.data
is kind of a disaster, in part because all of theNonEmptyX
types 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
NonEmptyCollection
interface 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
NonEmptyCollection
is 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
NonEmptyCollection
can't be, because of mistakes that we've made in the past. For example,NonEmptyChain
has agroupBy
that returns aNonEmptyMap
, while the otherNonEmptyX
collections call that methodgroupByNem
and havegroupBy
return aSortedSet
. AlsoChain
haslength
andsize
methods that return aLong
(?), whileNonEmptyChain
has aLong
-returninglength
, but nosize
(??), while the otherNonEmptyX
collections have alength
that returns anInt
(and some of them have asize: Int
). I can't wait forcats.data
to be banished to its own module in Cats 3.