From 0e8b0bd12777038ec5f8d10e28a3831393add3ce Mon Sep 17 00:00:00 2001 From: satorg Date: Fri, 15 Apr 2022 19:43:10 -0700 Subject: [PATCH] in coreJVM --- .../scala-2.13+/cats/data/NonEmptyLazyList.scala | 2 +- .../main/scala-2.13+/cats/instances/stream.scala | 2 +- .../main/scala/cats/arrow/FunctionKMacros.scala | 1 - .../src/main/scala/cats/compat/targetName.scala | 3 ++- core/src/main/scala/cats/ApplicativeError.scala | 9 ++++++++- core/src/main/scala/cats/TraverseFilter.scala | 7 ++++++- core/src/main/scala/cats/data/Const.scala | 3 ++- core/src/main/scala/cats/data/EitherT.scala | 11 ++++------- .../scala/cats/syntax/applicativeError.scala | 9 ++++++--- core/src/main/scala/cats/syntax/either.scala | 16 +++++++++++++--- 10 files changed, 43 insertions(+), 20 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 5591b8abded..218ab50a706 100644 --- a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala +++ b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala @@ -213,7 +213,7 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A]) * Tests if some element is contained in this NonEmptyLazyList */ final def contains(a: A)(implicit A: Eq[A]): Boolean = - toLazyList.contains(a) + exists(A.eqv(a, _)) /** * Tests whether a predicate holds for all elements diff --git a/core/src/main/scala-2.13+/cats/instances/stream.scala b/core/src/main/scala-2.13+/cats/instances/stream.scala index ad01c35758b..cc8687100ed 100644 --- a/core/src/main/scala-2.13+/cats/instances/stream.scala +++ b/core/src/main/scala-2.13+/cats/instances/stream.scala @@ -104,7 +104,7 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances { case Left(a) #:: tail => stack = fn(a) #::: tail advance() - case empty => + case _ => state = Right(None) } diff --git a/core/src/main/scala-2/src/main/scala/cats/arrow/FunctionKMacros.scala b/core/src/main/scala-2/src/main/scala/cats/arrow/FunctionKMacros.scala index 89dd8846bd4..51ed68ee7f6 100644 --- a/core/src/main/scala-2/src/main/scala/cats/arrow/FunctionKMacros.scala +++ b/core/src/main/scala-2/src/main/scala/cats/arrow/FunctionKMacros.scala @@ -22,7 +22,6 @@ package cats package arrow -import scala.language.experimental.macros import scala.reflect.macros.blackbox private[arrow] class FunctionKMacroMethods { diff --git a/core/src/main/scala-2/src/main/scala/cats/compat/targetName.scala b/core/src/main/scala-2/src/main/scala/cats/compat/targetName.scala index 44e0e795aaa..50ef43c2594 100644 --- a/core/src/main/scala-2/src/main/scala/cats/compat/targetName.scala +++ b/core/src/main/scala-2/src/main/scala/cats/compat/targetName.scala @@ -22,6 +22,7 @@ package cats.compat import scala.annotation.Annotation +import scala.annotation.nowarn // compat dummy so we can use targetName on scala 3 to get out of bincompat pickles -private[cats] class targetName(dummy: String) extends Annotation +private[cats] class targetName(@nowarn("cat=unused-params") dummy: String) extends Annotation diff --git a/core/src/main/scala/cats/ApplicativeError.scala b/core/src/main/scala/cats/ApplicativeError.scala index 847930d56e7..4c7eb925cb0 100644 --- a/core/src/main/scala/cats/ApplicativeError.scala +++ b/core/src/main/scala/cats/ApplicativeError.scala @@ -25,6 +25,7 @@ import cats.ApplicativeError.CatchOnlyPartiallyApplied import cats.data.{EitherT, Validated} import cats.data.Validated.{Invalid, Valid} +import scala.annotation.nowarn import scala.reflect.ClassTag import scala.util.control.NonFatal import scala.util.{Failure, Success, Try} @@ -353,7 +354,13 @@ object ApplicativeError { final private[cats] class CatchOnlyPartiallyApplied[T, F[_], E](private val F: ApplicativeError[F, E]) extends AnyVal { - def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T], ev: Throwable <:< E): F[A] = + + def apply[A](f: => A)(implicit + CT: ClassTag[T], + @nowarn("cat=unused-params") + NT: NotNull[T], + ev: Throwable <:< E + ): F[A] = try { F.pure(f) } catch { diff --git a/core/src/main/scala/cats/TraverseFilter.scala b/core/src/main/scala/cats/TraverseFilter.scala index 76628ac4088..d96eeaf7066 100644 --- a/core/src/main/scala/cats/TraverseFilter.scala +++ b/core/src/main/scala/cats/TraverseFilter.scala @@ -124,7 +124,12 @@ trait TraverseFilter[F[_]] extends FunctorFilter[F] { /** * Removes duplicate elements from a list, keeping only the first occurrence. - * This is usually faster than ordDistinct, especially for things that have a slow comparion (like String). + * This is usually faster than ordDistinct, especially for things that have a slow comparison (like String). + * + * @note the passed `Hash` typeclass is not currently in use. + * @todo replace `HashSet` from Scala library with one that can make use of the `Hash` typeclass + * instead of the Java's `hashCode` method. Consider a candidate implementation in + * [[https://github.com/typelevel/cats/pull/4185 PR#4185]]. */ def hashDistinct[A](fa: F[A])(implicit H: Hash[A]): F[A] = traverseFilter[State[HashSet[A], *], A, A](fa)(a => diff --git a/core/src/main/scala/cats/data/Const.scala b/core/src/main/scala/cats/data/Const.scala index 28626fa51a4..d6722f06910 100644 --- a/core/src/main/scala/cats/data/Const.scala +++ b/core/src/main/scala/cats/data/Const.scala @@ -23,6 +23,7 @@ package cats package data import cats.kernel.{CommutativeMonoid, CommutativeSemigroup, LowerBounded, UpperBounded} +import scala.annotation.nowarn /** * [[Const]] is a phantom type, it does not contain a value of its second type parameter `B` @@ -39,7 +40,7 @@ final case class Const[A, B](getConst: A) { def combine(that: Const[A, B])(implicit A: Semigroup[A]): Const[A, B] = Const(A.combine(getConst, that.getConst)) - def traverse[F[_], C](f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] = + def traverse[F[_], C](@nowarn("cat=unused-params") f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] = F.pure(retag[C]) def ===(that: Const[A, B])(implicit A: Eq[A]): Boolean = diff --git a/core/src/main/scala/cats/data/EitherT.scala b/core/src/main/scala/cats/data/EitherT.scala index bc59e634406..69932adccc2 100644 --- a/core/src/main/scala/cats/data/EitherT.scala +++ b/core/src/main/scala/cats/data/EitherT.scala @@ -986,7 +986,6 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 { type F[x] = Nested[P.F, Validated[E, *], x] implicit val monadM: Monad[M] = P.monad - implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither def applicative: Applicative[Nested[P.F, Validated[E, *], *]] = cats.data.Nested.catsDataApplicativeForNested(P.applicative, Validated.catsDataApplicativeErrorForValidated) @@ -1017,7 +1016,6 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 { type F[x] = Nested[P.F, Either[E, *], x] implicit val monadM: Monad[M] = P.monad - implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither def applicative: Applicative[Nested[P.F, Either[E, *], *]] = cats.data.Nested.catsDataApplicativeForNested(P.applicative, implicitly) @@ -1082,7 +1080,6 @@ abstract private[data] class EitherTInstances1 extends EitherTInstances2 { type F[x] = Nested[M, Validated[E, *], x] implicit val appValidated: Applicative[Validated[E, *]] = Validated.catsDataApplicativeErrorForValidated - implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither def applicative: Applicative[Nested[M, Validated[E, *], *]] = cats.data.Nested.catsDataApplicativeForNested[M, Validated[E, *]] @@ -1154,14 +1151,14 @@ private[data] trait EitherTSemigroupK[F[_], L] extends SemigroupK[EitherT[F, L, implicit val F: Monad[F] def combineK[A](x: EitherT[F, L, A], y: EitherT[F, L, A]): EitherT[F, L, A] = EitherT(F.flatMap(x.value) { - case l @ Left(_) => y.value - case r @ Right(_) => F.pure(r) + case r: Right[L, A] => F.pure(r) + case _ => y.value }) override def combineKEval[A](x: EitherT[F, L, A], y: Eval[EitherT[F, L, A]]): Eval[EitherT[F, L, A]] = Eval.now(EitherT(F.flatMap(x.value) { - case l @ Left(_) => y.value.value - case r @ Right(_) => F.pure(r: Either[L, A]) + case r: Right[L, A] => F.pure(r) + case _ => y.value.value })) } diff --git a/core/src/main/scala/cats/syntax/applicativeError.scala b/core/src/main/scala/cats/syntax/applicativeError.scala index ff12673bb6b..e81baaeeca3 100644 --- a/core/src/main/scala/cats/syntax/applicativeError.scala +++ b/core/src/main/scala/cats/syntax/applicativeError.scala @@ -24,15 +24,18 @@ package syntax import cats.data.{EitherT, Validated} +import scala.annotation.nowarn import scala.reflect.ClassTag trait ApplicativeErrorSyntax { implicit final def catsSyntaxApplicativeErrorId[E](e: E): ApplicativeErrorIdOps[E] = new ApplicativeErrorIdOps(e) - implicit final def catsSyntaxApplicativeError[F[_], E, A]( - fa: F[A] - )(implicit F: ApplicativeError[F, E]): ApplicativeErrorOps[F, E, A] = + implicit final def catsSyntaxApplicativeError[F[_], E, A](fa: F[A])(implicit + // Although not used directly but helps the compiler to deduce type `E`. + @nowarn("cat=unused-params") + F: ApplicativeError[F, E] + ): ApplicativeErrorOps[F, E, A] = new ApplicativeErrorOps[F, E, A](fa) } diff --git a/core/src/main/scala/cats/syntax/either.scala b/core/src/main/scala/cats/syntax/either.scala index 1c4a97e8a4e..220c0ce298e 100644 --- a/core/src/main/scala/cats/syntax/either.scala +++ b/core/src/main/scala/cats/syntax/either.scala @@ -24,6 +24,7 @@ package syntax import cats.data._ +import scala.annotation.nowarn import scala.reflect.ClassTag import scala.util.{Failure, Success, Try} import EitherSyntax._ @@ -47,7 +48,11 @@ object EitherSyntax { * Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics. */ final private[syntax] class CatchOnlyPartiallyApplied[T](private val dummy: Boolean = true) extends AnyVal { - def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T]): Either[T, A] = + def apply[A](f: => A)(implicit + CT: ClassTag[T], + @nowarn("cat=unused-params") + NT: NotNull[T] + ): Either[T, A] = try { Right(f) } catch { @@ -355,7 +360,7 @@ final class EitherOps[A, B](private val eab: Either[A, B]) extends AnyVal { def liftTo[F[_]](implicit F: ApplicativeError[F, _ >: A]): F[B] = F.fromEither(eab) } -final class EitherObjectOps(private val either: Either.type) extends AnyVal { +final class EitherObjectOps(private val either: Either.type) extends AnyVal with EitherObjectOpsBinCompat { def left[A, B](a: A): Either[A, B] = Left(a) def right[A, B](b: B): Either[A, B] = Right(b) @@ -366,7 +371,8 @@ final class EitherObjectOps(private val either: Either.type) extends AnyVal { def leftNes[A, B](a: A)(implicit O: Order[A]): EitherNes[A, B] = Left(NonEmptySet.one(a)) - def rightNes[A, B](b: B)(implicit O: Order[B]): EitherNes[A, B] = Right(b) + @deprecated("2.8.0", "Use rightNes without Order constraint") + protected def rightNes[A, B](b: B)(implicit O: Order[B]): EitherNes[A, B] = Right(b) def leftNel[A, B](a: A): EitherNel[A, B] = Left(NonEmptyList.one(a)) @@ -418,6 +424,10 @@ final class EitherObjectOps(private val either: Either.type) extends AnyVal { def unit[A]: Either[A, Unit] = EitherUtil.unit } +sealed private[syntax] trait EitherObjectOpsBinCompat extends Any { self: EitherObjectOps => + def rightNes[A, B](b: B): EitherNes[A, B] = Right(b) +} + final class LeftOps[A, B](private val left: Left[A, B]) extends AnyVal { /**