Skip to content

Commit

Permalink
in coreJVM
Browse files Browse the repository at this point in the history
  • Loading branch information
satorg committed Apr 16, 2022
1 parent 596d400 commit 0e8b0bd
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala-2.13+/cats/instances/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package cats
package arrow

import scala.language.experimental.macros
import scala.reflect.macros.blackbox

private[arrow] class FunctionKMacroMethods {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/scala/cats/TraverseFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/data/Const.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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 =
Expand Down
11 changes: 4 additions & 7 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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, *]]
Expand Down Expand Up @@ -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
}))
}

Expand Down
9 changes: 6 additions & 3 deletions core/src/main/scala/cats/syntax/applicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 13 additions & 3 deletions core/src/main/scala/cats/syntax/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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))

Expand Down Expand Up @@ -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 {

/**
Expand Down

0 comments on commit 0e8b0bd

Please sign in to comment.