Skip to content

Commit

Permalink
Move Ordering implicit into else
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartek committed Feb 1, 2025
1 parent b02647f commit 19f2d92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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 @@ -343,10 +343,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[B](f: A => B)(implicit O: Order[B]): NonEmptyList[A] = {
implicit val ord: Ordering[B] = O.toOrdering

if (tail.isEmpty) this
else {
implicit val ord: Ordering[B] = O.toOrdering

val bldr = List.newBuilder[A]
val seen = mutable.TreeSet.empty[B]
var rest = tail
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 @@ -239,10 +239,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[B](f: A => B)(implicit O: Order[B]): NonEmptySeq[A] = {
implicit val ord: Ordering[B] = O.toOrdering

if (toSeq.lengthCompare(1) == 0) this
else {
implicit val ord: Ordering[B] = O.toOrdering

val bldr = Seq.newBuilder[A]
val seen = mutable.TreeSet.empty[B]
val it = iterator
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 @@ -249,10 +249,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[B](f: A => B)(implicit O: Order[B]): NonEmptyVector[A] = {
implicit val ord: Ordering[B] = O.toOrdering

if (toVector.lengthCompare(1) == 0) this
else {
implicit val ord: Ordering[B] = O.toOrdering

val bldr = Vector.newBuilder[A]
val seen = mutable.TreeSet.empty[B]
val it = iterator
Expand Down

0 comments on commit 19f2d92

Please sign in to comment.