Skip to content

Commit

Permalink
Simplify type signature of distinctBy
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersaurus committed Jun 5, 2024
1 parent 096f4b3 commit a39d75f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])
*/
override def distinct[AA >: A](implicit O: Order[AA]): NonEmptyLazyList[AA] = distinctBy(identity[AA])

override def distinctBy[AA >: A, B](f: A => B)(implicit O: Order[B]): NonEmptyLazyList[AA] = {
override def distinctBy[B](f: A => B)(implicit O: Order[B]): NonEmptyLazyList[A] = {
implicit val ord: Ordering[B] = O.toOrdering

val buf = LazyList.newBuilder[AA]
val buf = LazyList.newBuilder[A]
toLazyList.foldLeft(TreeSet.empty[B]) { (elementsSoFar, a) =>
val b = f(a)
if (elementsSoFar(b)) elementsSoFar
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/NonEmptyChain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ class NonEmptyChainOps[A](private val value: NonEmptyChain[A])
final def distinct[AA >: A](implicit O: Order[AA]): NonEmptyChain[AA] =
distinctBy(identity[AA])

final def distinctBy[AA >: A, B](f: A => B)(implicit O: Order[B]): NonEmptyChain[AA] =
final def distinctBy[B](f: A => B)(implicit O: Order[B]): NonEmptyChain[A] =
create(toChain.distinctBy[B](f))

final def sortBy[B](f: A => B)(implicit B: Order[B]): NonEmptyChain[A] = create(toChain.sortBy(f))
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/NonEmptyCollection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private[cats] trait NonEmptyCollection[+A, U[+_], NE[+_]] extends Any {
def zipWithIndex: NE[(A, Int)]

def distinct[AA >: A](implicit O: Order[AA]): NE[AA]
def distinctBy[AA >: A, B](f: A => B)(implicit O: Order[B]): NE[AA]
def distinctBy[B](f: A => B)(implicit O: Order[B]): NE[A]
def sortBy[B](f: A => B)(implicit B: Order[B]): NE[A]
def sorted[AA >: A](implicit AA: Order[AA]): NE[AA]
def groupByNem[B](f: A => B)(implicit B: Order[B]): NonEmptyMap[B, NE[A]]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) extends NonEmptyCollec
*/
override def distinct[AA >: A](implicit O: Order[AA]): NonEmptyList[AA] = distinctBy(identity[AA])

override def distinctBy[AA >: A, B](f: A => B)(implicit O: Order[B]): NonEmptyList[AA] = {
override def distinctBy[B](f: A => B)(implicit O: Order[B]): NonEmptyList[A] = {
implicit val ord: Ordering[B] = O.toOrdering

val buf = ListBuffer.empty[AA]
val buf = ListBuffer.empty[A]
tail.foldLeft(TreeSet(f(head): B)) { (elementsSoFar, a) =>
val b = f(a)
if (elementsSoFar(b)) elementsSoFar
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/NonEmptySeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ final class NonEmptySeq[+A] private (val toSeq: Seq[A]) extends AnyVal with NonE
*/
override def distinct[AA >: A](implicit O: Order[AA]): NonEmptySeq[AA] = distinctBy(identity[AA])

override def distinctBy[AA >: A, B](f: A => B)(implicit O: Order[B]): NonEmptySeq[AA] = {
override def distinctBy[B](f: A => B)(implicit O: Order[B]): NonEmptySeq[A] = {
implicit val ord: Ordering[B] = O.toOrdering

val buf = Seq.newBuilder[AA]
val buf = Seq.newBuilder[A]
tail.foldLeft(TreeSet(f(head): B)) { (elementsSoFar, a) =>
val b = f(a)
if (elementsSoFar(b)) elementsSoFar
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A])
*/
override def distinct[AA >: A](implicit O: Order[AA]): NonEmptyVector[AA] = distinctBy(identity[AA])

override def distinctBy[AA >: A, B](f: A => B)(implicit O: Order[B]): NonEmptyVector[AA] = {
override def distinctBy[B](f: A => B)(implicit O: Order[B]): NonEmptyVector[A] = {
implicit val ord: Ordering[B] = O.toOrdering

val buf = Vector.newBuilder[AA]
val buf = Vector.newBuilder[A]
tail.foldLeft(TreeSet(f(head): B)) { (elementsSoFar, a) =>
val b = f(a)
if (elementsSoFar(b)) elementsSoFar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class NonEmptyLazyListSuite extends NonEmptyCollectionSuite[LazyList, NonEmptyLa
checkAll(s"NonEmptyLazyList[Int]", HashTests[NonEmptyLazyList[Int]].hash)
checkAll(s"Hash[NonEmptyLazyList[Int]]", SerializableTests.serializable(Hash[NonEmptyLazyList[Int]]))

checkAll("NonEmptyLazyList[Int]", NonEmptyAlternativeTests[NonEmptyLazyList].nonEmptyAlternative[Int, Int, Int])
checkAll("NonEmptyLazyList[Int]", NonEmptyAlternativeTests[NonEmptyLazyList].nonEmptyAlternative[Int, Int, Int])
checkAll("NonEmptyAlternative[NonEmptyLazyList]",
SerializableTests.serializable(NonEmptyAlternative[NonEmptyLazyList])
Expand Down

0 comments on commit a39d75f

Please sign in to comment.