From a39d75fca080a30510aae8e989ff19b0d4649daf Mon Sep 17 00:00:00 2001 From: Tim Golding Date: Wed, 5 Jun 2024 11:32:57 +0100 Subject: [PATCH] Simplify type signature of distinctBy --- core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala | 4 ++-- core/src/main/scala/cats/data/NonEmptyChain.scala | 2 +- core/src/main/scala/cats/data/NonEmptyCollection.scala | 2 +- core/src/main/scala/cats/data/NonEmptyList.scala | 4 ++-- core/src/main/scala/cats/data/NonEmptySeq.scala | 4 ++-- core/src/main/scala/cats/data/NonEmptyVector.scala | 4 ++-- .../test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala | 1 - 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala index 08ee02dc40..6faf08c5b6 100644 --- a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala +++ b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala @@ -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 diff --git a/core/src/main/scala/cats/data/NonEmptyChain.scala b/core/src/main/scala/cats/data/NonEmptyChain.scala index 094d0efdd0..3ab876bc43 100644 --- a/core/src/main/scala/cats/data/NonEmptyChain.scala +++ b/core/src/main/scala/cats/data/NonEmptyChain.scala @@ -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)) diff --git a/core/src/main/scala/cats/data/NonEmptyCollection.scala b/core/src/main/scala/cats/data/NonEmptyCollection.scala index b71660ef3c..6debb0e055 100644 --- a/core/src/main/scala/cats/data/NonEmptyCollection.scala +++ b/core/src/main/scala/cats/data/NonEmptyCollection.scala @@ -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]] diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index 498ecb7ded..b86ac76ec9 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -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 diff --git a/core/src/main/scala/cats/data/NonEmptySeq.scala b/core/src/main/scala/cats/data/NonEmptySeq.scala index 55632f9e34..65d76440fb 100644 --- a/core/src/main/scala/cats/data/NonEmptySeq.scala +++ b/core/src/main/scala/cats/data/NonEmptySeq.scala @@ -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 diff --git a/core/src/main/scala/cats/data/NonEmptyVector.scala b/core/src/main/scala/cats/data/NonEmptyVector.scala index d671f536fc..b2cca67fe1 100644 --- a/core/src/main/scala/cats/data/NonEmptyVector.scala +++ b/core/src/main/scala/cats/data/NonEmptyVector.scala @@ -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 diff --git a/tests/shared/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala b/tests/shared/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala index 2ecd733d39..6043bb870e 100644 --- a/tests/shared/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala +++ b/tests/shared/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala @@ -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])