Skip to content

Commit 3fc74ea

Browse files
committed
in coreJVM
1 parent 596d400 commit 3fc74ea

21 files changed

+95
-60
lines changed

core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])
213213
* Tests if some element is contained in this NonEmptyLazyList
214214
*/
215215
final def contains(a: A)(implicit A: Eq[A]): Boolean =
216-
toLazyList.contains(a)
216+
exists(A.eqv(a, _))
217217

218218
/**
219219
* Tests whether a predicate holds for all elements

core/src/main/scala-2.13+/cats/instances/stream.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances {
104104
case Left(a) #:: tail =>
105105
stack = fn(a) #::: tail
106106
advance()
107-
case empty =>
107+
case _ =>
108108
state = Right(None)
109109
}
110110

core/src/main/scala-2/src/main/scala/cats/arrow/FunctionKMacros.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
package cats
2323
package arrow
2424

25-
import scala.language.experimental.macros
2625
import scala.reflect.macros.blackbox
2726

2827
private[arrow] class FunctionKMacroMethods {

core/src/main/scala-2/src/main/scala/cats/compat/targetName.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package cats.compat
2323

2424
import scala.annotation.Annotation
25+
import scala.annotation.nowarn
2526

2627
// compat dummy so we can use targetName on scala 3 to get out of bincompat pickles
27-
private[cats] class targetName(dummy: String) extends Annotation
28+
private[cats] class targetName(@nowarn("cat=unused-params") dummy: String) extends Annotation

core/src/main/scala/cats/ApplicativeError.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import cats.ApplicativeError.CatchOnlyPartiallyApplied
2525
import cats.data.{EitherT, Validated}
2626
import cats.data.Validated.{Invalid, Valid}
2727

28+
import scala.annotation.nowarn
2829
import scala.reflect.ClassTag
2930
import scala.util.control.NonFatal
3031
import scala.util.{Failure, Success, Try}
@@ -353,7 +354,13 @@ object ApplicativeError {
353354

354355
final private[cats] class CatchOnlyPartiallyApplied[T, F[_], E](private val F: ApplicativeError[F, E])
355356
extends AnyVal {
356-
def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T], ev: Throwable <:< E): F[A] =
357+
358+
def apply[A](f: => A)(implicit
359+
CT: ClassTag[T],
360+
@nowarn("cat=unused-params")
361+
NT: NotNull[T],
362+
ev: Throwable <:< E
363+
): F[A] =
357364
try {
358365
F.pure(f)
359366
} catch {

core/src/main/scala/cats/TraverseFilter.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ trait TraverseFilter[F[_]] extends FunctorFilter[F] {
124124

125125
/**
126126
* Removes duplicate elements from a list, keeping only the first occurrence.
127-
* This is usually faster than ordDistinct, especially for things that have a slow comparion (like String).
127+
* This is usually faster than ordDistinct, especially for things that have a slow comparison (like String).
128+
*
129+
* @note the passed `Hash` typeclass is not currently in use.
130+
* @todo replace `HashSet` from Scala library with one that can make use of the `Hash` typeclass
131+
* instead of the Java's `hashCode` method. Consider a candidate implementation in
132+
* [[https://github.com/typelevel/cats/pull/4185 PR#4185]].
128133
*/
129134
def hashDistinct[A](fa: F[A])(implicit H: Hash[A]): F[A] =
130135
traverseFilter[State[HashSet[A], *], A, A](fa)(a =>

core/src/main/scala/cats/data/Const.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package cats
2323
package data
2424

2525
import cats.kernel.{CommutativeMonoid, CommutativeSemigroup, LowerBounded, UpperBounded}
26+
import scala.annotation.nowarn
2627

2728
/**
2829
* [[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) {
3940
def combine(that: Const[A, B])(implicit A: Semigroup[A]): Const[A, B] =
4041
Const(A.combine(getConst, that.getConst))
4142

42-
def traverse[F[_], C](f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] =
43+
def traverse[F[_], C](@nowarn("cat=unused-params") f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] =
4344
F.pure(retag[C])
4445

4546
def ===(that: Const[A, B])(implicit A: Eq[A]): Boolean =

core/src/main/scala/cats/data/EitherT.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,6 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
986986
type F[x] = Nested[P.F, Validated[E, *], x]
987987

988988
implicit val monadM: Monad[M] = P.monad
989-
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither
990989

991990
def applicative: Applicative[Nested[P.F, Validated[E, *], *]] =
992991
cats.data.Nested.catsDataApplicativeForNested(P.applicative, Validated.catsDataApplicativeErrorForValidated)
@@ -1017,7 +1016,6 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
10171016
type F[x] = Nested[P.F, Either[E, *], x]
10181017

10191018
implicit val monadM: Monad[M] = P.monad
1020-
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither
10211019

10221020
def applicative: Applicative[Nested[P.F, Either[E, *], *]] =
10231021
cats.data.Nested.catsDataApplicativeForNested(P.applicative, implicitly)
@@ -1082,7 +1080,6 @@ abstract private[data] class EitherTInstances1 extends EitherTInstances2 {
10821080
type F[x] = Nested[M, Validated[E, *], x]
10831081

10841082
implicit val appValidated: Applicative[Validated[E, *]] = Validated.catsDataApplicativeErrorForValidated
1085-
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither
10861083

10871084
def applicative: Applicative[Nested[M, Validated[E, *], *]] =
10881085
cats.data.Nested.catsDataApplicativeForNested[M, Validated[E, *]]
@@ -1154,14 +1151,14 @@ private[data] trait EitherTSemigroupK[F[_], L] extends SemigroupK[EitherT[F, L,
11541151
implicit val F: Monad[F]
11551152
def combineK[A](x: EitherT[F, L, A], y: EitherT[F, L, A]): EitherT[F, L, A] =
11561153
EitherT(F.flatMap(x.value) {
1157-
case l @ Left(_) => y.value
1158-
case r @ Right(_) => F.pure(r)
1154+
case r: Right[L, A] => F.pure(r)
1155+
case _ => y.value
11591156
})
11601157

11611158
override def combineKEval[A](x: EitherT[F, L, A], y: Eval[EitherT[F, L, A]]): Eval[EitherT[F, L, A]] =
11621159
Eval.now(EitherT(F.flatMap(x.value) {
1163-
case l @ Left(_) => y.value.value
1164-
case r @ Right(_) => F.pure(r: Either[L, A])
1160+
case r: Right[L, A] => F.pure(r)
1161+
case _ => y.value.value
11651162
}))
11661163
}
11671164

core/src/main/scala/cats/data/Func.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ sealed private[data] trait FuncApply[F[_], C] extends Apply[λ[α => Func[F, C,
113113
sealed private[data] trait FuncApplicative[F[_], C] extends Applicative[λ[α => Func[F, C, α]]] with FuncApply[F, C] {
114114
def F: Applicative[F]
115115
def pure[A](a: A): Func[F, C, A] =
116-
Func.func(c => F.pure(a))
116+
Func.func(_ => F.pure(a))
117117
}
118118

119119
/**
@@ -167,5 +167,5 @@ sealed private[data] trait AppFuncApplicative[F[_], C] extends Applicative[λ[α
167167
override def product[A, B](fa: AppFunc[F, C, A], fb: AppFunc[F, C, B]): AppFunc[F, C, (A, B)] =
168168
Func.appFunc[F, C, (A, B)](c => F.product(fa.run(c), fb.run(c)))(F)
169169
def pure[A](a: A): AppFunc[F, C, A] =
170-
Func.appFunc[F, C, A](c => F.pure(a))(F)
170+
Func.appFunc[F, C, A](_ => F.pure(a))(F)
171171
}

core/src/main/scala/cats/data/IndexedReaderWriterStateT.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ final class IndexedReaderWriterStateT[F[_], E, L, SA, SB, A](val runF: F[(E, SA)
246246
* Inspect a value from the input state, without modifying the state.
247247
*/
248248
def inspect[B](f: SB => B)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B] =
249-
transform { (l, sb, a) =>
249+
transform { (l, sb, _) =>
250250
(l, sb, f(sb))
251251
}
252252

@@ -287,7 +287,7 @@ final class IndexedReaderWriterStateT[F[_], E, L, SA, SB, A](val runF: F[(E, SA)
287287
* Retrieve the value written to the log.
288288
*/
289289
def written(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, L] =
290-
transform { (l, sb, a) =>
290+
transform { (l, sb, _) =>
291291
(l, sb, l)
292292
}
293293

@@ -555,7 +555,11 @@ abstract private[data] class RWSFunctions {
555555
/**
556556
* Return `a` and an empty log without modifying the input state.
557557
*/
558-
def apply[E, L: Monoid, S, A](f: (E, S) => (L, S, A)): ReaderWriterState[E, L, S, A] =
558+
def apply[E, L, S, A](f: (E, S) => (L, S, A)): ReaderWriterState[E, L, S, A] =
559+
ReaderWriterStateT.applyF(Now((e, s) => Now(f(e, s))))
560+
561+
@deprecated("2.8.0", "Use apply without the Monoid constraint")
562+
protected def apply[E, L: Monoid, S, A](f: (E, S) => (L, S, A)): ReaderWriterState[E, L, S, A] =
559563
ReaderWriterStateT.applyF(Now((e, s) => Now(f(e, s))))
560564

561565
/**

core/src/main/scala/cats/data/IndexedStateT.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ sealed abstract private[data] class IndexedStateTContravariantMonoidal[F[_], S]
483483
implicit def G: Applicative[F]
484484

485485
override def unit: IndexedStateT[F, S, S, Unit] =
486-
IndexedStateT.applyF(G.pure((s: S) => F.trivial[(S, Unit)]))
486+
IndexedStateT.applyF(G.pure((_: S) => F.trivial[(S, Unit)]))
487487

488488
override def contramap[A, B](fa: IndexedStateT[F, S, S, A])(f: B => A): IndexedStateT[F, S, S, B] =
489489
contramap2(fa, trivial)(((a: A) => (a, a)).compose(f))

core/src/main/scala/cats/data/Ior.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ sealed abstract class Ior[+A, +B] extends Product with Serializable {
775775

776776
final def ===[AA >: A, BB >: B](that: AA Ior BB)(implicit AA: Eq[AA], BB: Eq[BB]): Boolean =
777777
fold(
778-
a => that.fold(a2 => AA.eqv(a, a2), b2 => false, (a2, b2) => false),
779-
b => that.fold(a2 => false, b2 => BB.eqv(b, b2), (a2, b2) => false),
780-
(a, b) => that.fold(a2 => false, b2 => false, (a2, b2) => AA.eqv(a, a2) && BB.eqv(b, b2))
778+
a => that.fold(a2 => AA.eqv(a, a2), _ => false, (_, _) => false),
779+
b => that.fold(_ => false, b2 => BB.eqv(b, b2), (_, _) => false),
780+
(a, b) => that.fold(_ => false, _ => false, (a2, b2) => AA.eqv(a, a2) && BB.eqv(b, b2))
781781
)
782782

783783
final def compare[AA >: A, BB >: B](that: AA Ior BB)(implicit AA: Order[AA], BB: Order[BB]): Int =
@@ -929,9 +929,9 @@ sealed abstract private[data] class IorInstances extends IorInstances0 {
929929
}
930930
case Ior.Left(e1) =>
931931
ff match {
932-
case Ior.Right(f) => Ior.Left(e1)
933-
case Ior.Both(e2, f) => Ior.Left(E.combine(e2, e1))
932+
case Ior.Both(e2, _) => Ior.Left(E.combine(e2, e1))
934933
case Ior.Left(e2) => Ior.Left(E.combine(e2, e1))
934+
case _ => Ior.Left(e1)
935935
}
936936
}
937937
}

core/src/main/scala/cats/data/NonEmptySet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ sealed abstract private[data] class NonEmptySetInstances extends NonEmptySetInst
428428
}
429429

430430
sealed abstract private[data] class NonEmptySetInstances0 extends NonEmptySetInstances1 {
431-
implicit def catsDataHashForNonEmptySet[A: Order: Hash]: Hash[NonEmptySet[A]] =
431+
implicit def catsDataHashForNonEmptySet[A: Hash]: Hash[NonEmptySet[A]] =
432432
Hash[SortedSet[A]].asInstanceOf[Hash[NonEmptySet[A]]]
433433
}
434434

core/src/main/scala/cats/data/RepresentableStore.scala

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,25 @@ final case class RepresentableStore[F[_], S, A](fa: F[A], index: S)(implicit R:
9595

9696
object RepresentableStore {
9797

98-
implicit def catsDataRepresentableStoreComonad[F[_], S](implicit
99-
R: Representable[F]
100-
): Comonad[RepresentableStore[F, S, *]] =
101-
new Comonad[RepresentableStore[F, S, *]] {
102-
override def extract[B](x: RepresentableStore[F, S, B]): B =
103-
x.extract
104-
105-
override def coflatMap[A, B](
106-
fa: RepresentableStore[F, S, A]
107-
)(f: RepresentableStore[F, S, A] => B): RepresentableStore[F, S, B] =
108-
fa.coflatten.map(f)
109-
110-
override def map[A, B](fa: RepresentableStore[F, S, A])(f: A => B): RepresentableStore[F, S, B] =
111-
fa.map(f)
112-
}
98+
implicit def catsDataRepresentableStoreComonadBinCompat[F[_], S]: Comonad[RepresentableStore[F, S, *]] =
99+
new RepresentableStoreComonad[F, S]
100+
101+
@deprecated("Use catsDataRepresentableStoreComonadBinCompat instead", "2.8.0")
102+
def catsDataRepresentableStoreComonad[F[_], S](R: Representable[F]): Comonad[RepresentableStore[F, S, *]] =
103+
new RepresentableStoreComonad[F, S]
104+
105+
final private class RepresentableStoreComonad[F[_], S] private[RepresentableStore]
106+
extends Comonad[RepresentableStore[F, S, *]] {
107+
108+
override def extract[B](x: RepresentableStore[F, S, B]): B =
109+
x.extract
110+
111+
override def coflatMap[A, B](
112+
fa: RepresentableStore[F, S, A]
113+
)(f: RepresentableStore[F, S, A] => B): RepresentableStore[F, S, B] =
114+
fa.coflatten.map(f)
115+
116+
override def map[A, B](fa: RepresentableStore[F, S, A])(f: A => B): RepresentableStore[F, S, B] =
117+
fa.map(f)
118+
}
113119
}

core/src/main/scala/cats/data/Validated.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package data
2525
import cats.data.Validated.{Invalid, Valid}
2626
import cats.kernel.CommutativeSemigroup
2727

28+
import scala.annotation.nowarn
2829
import scala.reflect.ClassTag
2930
import scala.util.{Failure, Success, Try}
3031

@@ -859,7 +860,11 @@ object Validated extends ValidatedInstances with ValidatedFunctions with Validat
859860
final private[data] class CatchOnlyPartiallyApplied[T](private val dummy: Boolean = true) extends AnyVal {
860861
/* Note: the NT parameter is not referenced at runtime, but serves a compile-time role.
861862
* See https://github.com/typelevel/cats/pull/1867/files#r138381991 for details. */
862-
def apply[A](f: => A)(implicit T: ClassTag[T], NT: NotNull[T]): Validated[T, A] =
863+
def apply[A](f: => A)(implicit
864+
T: ClassTag[T],
865+
@nowarn("cat=unused-params")
866+
NT: NotNull[T]
867+
): Validated[T, A] =
863868
try {
864869
valid(f)
865870
} catch {
@@ -894,13 +899,13 @@ sealed abstract private[data] class ValidatedInstances extends ValidatedInstance
894899
fa match {
895900
case Invalid(e) =>
896901
fb match {
897-
case Invalid(e2) => Invalid(Semigroup[E].combine(e, e2))
898902
case Valid(b) => Valid(f(Ior.right(b)))
903+
case Invalid(e2) => Invalid(Semigroup[E].combine(e, e2))
899904
}
900905
case Valid(a) =>
901906
fb match {
902-
case Invalid(e) => Valid(f(Ior.left(a)))
903-
case Valid(b) => Valid(f(Ior.both(a, b)))
907+
case Valid(b) => Valid(f(Ior.both(a, b)))
908+
case _ => Valid(f(Ior.left(a)))
904909
}
905910
}
906911
}

core/src/main/scala/cats/instances/either.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
189189

190190
override def alignWith[B, C, D](fb: Either[A, B], fc: Either[A, C])(f: Ior[B, C] => D): Either[A, D] =
191191
fb match {
192-
case left @ Left(a) =>
192+
case left: Left[A, B] =>
193193
fc match {
194-
case Left(_) => left.rightCast[D]
195194
case Right(c) => Right(f(Ior.right(c)))
195+
case _ => left.rightCast[D]
196196
}
197197
case Right(b) =>
198198
fc match {
199-
case Left(a) => Right(f(Ior.left(b)))
200199
case Right(c) => Right(f(Ior.both(b, c)))
200+
case _ => Right(f(Ior.left(b)))
201201
}
202202
}
203203

core/src/main/scala/cats/instances/map.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait MapInstances extends cats.kernel.instances.MapInstances {
7979
fa.flatMap { case (k, a) => f(a).get(k).map((k, _)) }
8080

8181
def unorderedFoldMap[A, B: CommutativeMonoid](fa: Map[K, A])(f: (A) => B) =
82-
fa.foldLeft(Monoid[B].empty) { case (b, (k, a)) => Monoid[B].combine(b, f(a)) }
82+
fa.foldLeft(Monoid[B].empty) { case (b, (_, a)) => Monoid[B].combine(b, f(a)) }
8383

8484
def tailRecM[A, B](a: A)(f: A => Map[K, Either[A, B]]): Map[K, B] = {
8585
val bldr = Map.newBuilder[K, B]

core/src/main/scala/cats/instances/sortedMap.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ class SortedMapEq[K, V](implicit V: Eq[V], O: Order[K]) extends cats.kernel.inst
201201
@deprecated("Use cats.kernel.instances.SortedMapCommutativeMonoid", "2.0.0-RC2")
202202
class SortedMapCommutativeMonoid[K, V](implicit V: CommutativeSemigroup[V], O: Order[K])
203203
extends SortedMapMonoid[K, V]
204-
with CommutativeMonoid[SortedMap[K, V]] {
205-
private[this] val underlying: CommutativeMonoid[SortedMap[K, V]] =
206-
new cats.kernel.instances.SortedMapCommutativeMonoid[K, V]
207-
}
204+
with CommutativeMonoid[SortedMap[K, V]]
208205

209206
@deprecated("Use cats.kernel.instances.SortedMapMonoid", "2.0.0-RC2")
210207
class SortedMapMonoid[K, V](implicit V: Semigroup[V], O: Order[K]) extends cats.kernel.instances.SortedMapMonoid[K, V]

core/src/main/scala/cats/syntax/applicativeError.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ package syntax
2424

2525
import cats.data.{EitherT, Validated}
2626

27+
import scala.annotation.nowarn
2728
import scala.reflect.ClassTag
2829

2930
trait ApplicativeErrorSyntax {
3031
implicit final def catsSyntaxApplicativeErrorId[E](e: E): ApplicativeErrorIdOps[E] =
3132
new ApplicativeErrorIdOps(e)
3233

33-
implicit final def catsSyntaxApplicativeError[F[_], E, A](
34-
fa: F[A]
35-
)(implicit F: ApplicativeError[F, E]): ApplicativeErrorOps[F, E, A] =
34+
implicit final def catsSyntaxApplicativeError[F[_], E, A](fa: F[A])(implicit
35+
// Although not used directly but helps the compiler to deduce type `E`.
36+
@nowarn("cat=unused-params")
37+
F: ApplicativeError[F, E]
38+
): ApplicativeErrorOps[F, E, A] =
3639
new ApplicativeErrorOps[F, E, A](fa)
3740
}
3841

0 commit comments

Comments
 (0)