Skip to content

Commit

Permalink
Merge pull request #4508 from xuwei-k/explicit-type-Scala-2-13-12
Browse files Browse the repository at this point in the history
add explicit type
  • Loading branch information
danicheg authored Sep 8, 2023
2 parents b1a50e0 + 4582203 commit e0f0b40
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 36 deletions.
8 changes: 5 additions & 3 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ trait Foldable[F[_]] extends UnorderedFoldable[F] with FoldableNFunctions[F] { s
}

object Foldable {
private val sentinel: Function1[Any, Any] = new scala.runtime.AbstractFunction1[Any, Any] { def apply(a: Any) = this }
private val sentinel: Function1[Any, Any] = new scala.runtime.AbstractFunction1[Any, Any] {
def apply(a: Any): Any = this
}

def iterateRight[A, B](iterable: Iterable[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = {
def loop(it: Iterator[A]): Eval[B] =
Expand Down Expand Up @@ -979,12 +981,12 @@ object Foldable {

private[cats] object Source {
val Empty: Source[Nothing] = new Source[Nothing] {
def uncons = None
def uncons: Option[(Nothing, Eval[Source[Nothing]])] = None
}

def cons[A](a: A, src: Eval[Source[A]]): Source[A] =
new Source[A] {
def uncons = Some((a, src))
def uncons: Option[(A, Eval[Source[A]])] = Some((a, src))
}

def fromFoldable[F[_], A](fa: F[A])(implicit F: Foldable[F]): Source[A] =
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/Inject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ sealed abstract private[cats] class InjectInstances {
new Inject[A, A] {
val inj = identity(_: A)

val prj = Some(_: A)
val prj: A => Option[A] = Some(_: A)
}

implicit def catsLeftInjectInstance[A, B]: Inject[A, Either[A, B]] =
new Inject[A, Either[A, B]] {
val inj = Left(_: A)
val inj: A => Either[A, B] = Left(_: A)

val prj = (_: Either[A, B]).left.toOption
}

implicit def catsRightInjectInstance[A, B, C](implicit I: Inject[A, B]): Inject[A, Either[C, B]] =
new Inject[A, Either[C, B]] {
val inj = (a: A) => Right(I.inj(a))
val inj: A => Either[C, B] = (a: A) => Right(I.inj(a))

val prj = (_: Either[C, B]).toOption.flatMap(I.prj)
}
Expand Down
22 changes: 14 additions & 8 deletions core/src/main/scala/cats/InjectK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,32 @@ sealed abstract private[cats] class InjectKInstances {
new InjectK[F, F] {
val inj = FunctionK.id[F]

val prj = new FunctionK[F, λ[α => Option[F[α]]]] { def apply[A](a: F[A]): Option[F[A]] = Some(a) }
val prj: FunctionK[F, λ[α => Option[F[α]]]] = new FunctionK[F, λ[α => Option[F[α]]]] {
def apply[A](a: F[A]): Option[F[A]] = Some(a)
}
}

implicit def catsLeftInjectKInstance[F[_], G[_]]: InjectK[F, EitherK[F, G, *]] =
new InjectK[F, EitherK[F, G, *]] {
val inj = new FunctionK[F, EitherK[F, G, *]] { def apply[A](a: F[A]): EitherK[F, G, A] = EitherK.leftc(a) }

val prj = new FunctionK[EitherK[F, G, *], λ[α => Option[F[α]]]] {
def apply[A](a: EitherK[F, G, A]): Option[F[A]] = a.run.left.toOption
val inj: FunctionK[F, EitherK[F, G, *]] = new FunctionK[F, EitherK[F, G, *]] {
def apply[A](a: F[A]): EitherK[F, G, A] = EitherK.leftc(a)
}

val prj: FunctionK[EitherK[F, G, *], λ[α => Option[F[α]]]] =
new FunctionK[EitherK[F, G, *], λ[α => Option[F[α]]]] {
def apply[A](a: EitherK[F, G, A]): Option[F[A]] = a.run.left.toOption
}
}

implicit def catsRightInjectKInstance[F[_], G[_], H[_]](implicit I: InjectK[F, G]): InjectK[F, EitherK[H, G, *]] =
new InjectK[F, EitherK[H, G, *]] {
val inj = new FunctionK[G, EitherK[H, G, *]] { def apply[A](a: G[A]): EitherK[H, G, A] = EitherK.rightc(a) }
.compose(I.inj)

val prj = new FunctionK[EitherK[H, G, *], λ[α => Option[F[α]]]] {
def apply[A](a: EitherK[H, G, A]): Option[F[A]] = a.run.toOption.flatMap(I.prj(_))
}
val prj: FunctionK[EitherK[H, G, *], λ[α => Option[F[α]]]] =
new FunctionK[EitherK[H, G, *], λ[α => Option[F[α]]]] {
def apply[A](a: EitherK[H, G, A]): Option[F[A]] = a.run.toOption.flatMap(I.prj(_))
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ sealed abstract class Chain[+A] extends ChainCompat[A] {
@suppressUnusedImportWarningForScalaVersionSpecific
object Chain extends ChainInstances with ChainCompanionCompat {

private val sentinel: Function1[Any, Any] = new scala.runtime.AbstractFunction1[Any, Any] { def apply(a: Any) = this }
private val sentinel: Function1[Any, Any] = new scala.runtime.AbstractFunction1[Any, Any] {
def apply(a: Any): Any = this
}

sealed abstract private[data] class NonEmpty[A] extends Chain[A]

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Nested.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sealed abstract private[data] class NestedInstances0 extends NestedInstances1 {
): Representable.Aux[Nested[F, G, *], (F0.Representation, G0.Representation)] = new Representable[Nested[F, G, *]] {
val FG = F0.compose(G0)

val F = new NestedFunctor[F, G] {
val F: Functor[Nested[F, G, *]] = new NestedFunctor[F, G] {
val FG = F0.F.compose(G0.F)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Tuple2K.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ sealed abstract private[data] class Tuple2KInstances1 extends Tuple2KInstances2
new Representable[Tuple2K[F, G, *]] {
type Representation = Either[FF.Representation, GG.Representation]

val F = new Tuple2KFunctor[F, G] {
val F: Functor[Tuple2K[F, G, *]] = new Tuple2KFunctor[F, G] {
val F = FF.F
val G = GG.F
}
Expand Down
8 changes: 4 additions & 4 deletions free/src/main/scala/cats/free/FreeT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ sealed abstract private[free] class FreeTInstances extends FreeTInstances0 {
E: MonadError[M, E]
): MonadError[FreeT[S, M, *], E] =
new MonadError[FreeT[S, M, *], E] with FreeTMonad[S, M] {
override def M = E
override def M: Applicative[M] = E
override def handleErrorWith[A](fa: FreeT[S, M, A])(f: E => FreeT[S, M, A]) =
FreeT.liftT[S, M, FreeT[S, M, A]](E.handleErrorWith(fa.toM)(f.andThen(_.toM)))(M).flatMap(identity)
override def raiseError[A](e: E) =
Expand All @@ -294,7 +294,7 @@ sealed abstract private[free] class FreeTInstances extends FreeTInstances0 {
S: Functor[S]
): MonadError[FreeT[S, M, *], E] =
new MonadError[FreeT[S, M, *], E] with FreeTMonad[S, M] {
override def M = E
override def M: Applicative[M] = E

private[this] val RealDefer = catsDeferForFreeT[S, M]

Expand Down Expand Up @@ -362,8 +362,8 @@ sealed abstract private[free] class FreeTInstances1 extends FreeTInstances2 {
sealed abstract private[free] class FreeTInstances2 extends FreeTInstances3 {
implicit def catsFreeAlternativeForFreeT[S[_], M[_]: Alternative: Monad]: Alternative[FreeT[S, M, *]] =
new Alternative[FreeT[S, M, *]] with FreeTMonad[S, M] with FreeTMonoidK[S, M] {
override def M = Alternative[M]
override def M1 = Alternative[M]
override def M: Applicative[M] = Alternative[M]
override def M1: MonoidK[M] = Alternative[M]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object BoundedEnumerableLaws {
new BoundedEnumerableLaws[A] {
val B: LowerBounded[A] with UpperBounded[A] = ev
val E = ev.order
val N = ev
val P = ev
val N: PartialNext[A] = ev
val P: PartialPrevious[A] = ev
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ListMonoid[A] extends Monoid[List[A]] { self =>
item ::: acc
}

override def reverse = self
override def reverse: Monoid[List[A]] = self
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ class StringMonoid extends Monoid[String] { self =>
self.combineAll(revStrings)
}

override def reverse = self
override def reverse: Monoid[String] = self
}
}
5 changes: 3 additions & 2 deletions laws/src/main/scala/cats/laws/discipline/ApplyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ package discipline

import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._
import Prop.*
import org.typelevel.discipline.Laws

trait ApplyTests[F[_]] extends FunctorTests[F] with SemigroupalTests[F] {
def laws: ApplyLaws[F]
Expand All @@ -47,7 +48,7 @@ trait ApplyTests[F[_]] extends FunctorTests[F] with SemigroupalTests[F] {
new RuleSet {
val name = "apply"
val parents = Seq(functor[A, B, C], semigroupal[A, B, C])
val bases = Seq.empty
val bases: Seq[(String, Laws#RuleSet)] = Seq.empty
val props = Seq(
"apply composition" -> forAll(laws.applyComposition[A, B, C] _),
"map2/product-map consistency" -> forAll(laws.map2ProductConsistency[A, B, C] _),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package discipline

import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop.forAll
import org.typelevel.discipline.Laws

trait BitraverseTests[F[_, _]] extends BifoldableTests[F] with BifunctorTests[F] {
def laws: BitraverseLaws[F]
Expand Down Expand Up @@ -59,7 +60,7 @@ trait BitraverseTests[F[_, _]] extends BifoldableTests[F] with BifunctorTests[F]
new RuleSet {
val name = "bitraverse"
val parents = Seq(bifoldable[A, B, C], bifunctor[A, B, C, D, E, H])
val bases = Seq.empty
val bases: Seq[(String, Laws#RuleSet)] = Seq.empty
val props = Seq(
"bitraverse identity" -> forAll(laws.bitraverseIdentity[A, B] _),
"bitraverse composition" -> forAll(laws.bitraverseCompose[G, A, B, C, D, E, H] _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ package discipline
import cats.ContravariantMonoidal
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop._
import org.scalacheck.Prop.*
import org.typelevel.discipline.Laws

trait ContravariantMonoidalTests[F[_]] extends ContravariantSemigroupalTests[F] {
def laws: ContravariantMonoidalLaws[F]
Expand All @@ -47,7 +48,7 @@ trait ContravariantMonoidalTests[F[_]] extends ContravariantSemigroupalTests[F]
new RuleSet {
val name = "contravariantMonoidal"
val parents = Seq(contravariantSemigroupal[A, B, C])
val bases = Seq.empty
val bases: Seq[(String, Laws#RuleSet)] = Seq.empty
val props = Seq(
"contravariantMonoidal right unit" ->
forAll(laws.contravariantMonoidalUnitRight[A] _),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ package discipline
import cats.ContravariantSemigroupal
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop._
import org.scalacheck.Prop.*
import org.typelevel.discipline.Laws

trait ContravariantSemigroupalTests[F[_]] extends ContravariantTests[F] with SemigroupalTests[F] {
def laws: ContravariantSemigroupalLaws[F]
Expand All @@ -47,7 +48,7 @@ trait ContravariantSemigroupalTests[F[_]] extends ContravariantTests[F] with Sem
new RuleSet {
val name = "contravariantSemigroupal"
val parents = Seq(contravariant[A, B, C], semigroupal[A, B, C])
val bases = Seq.empty
val bases: Seq[(String, Laws#RuleSet)] = Seq.empty
val props = Seq(
"contravariantSemigroupal contramap2 delta associates" ->
forAll(laws.contravariantSemigroupalContramap2DiagonalAssociates[A] _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ package discipline

import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop._
import org.scalacheck.Prop.*
import org.typelevel.discipline.Laws

trait InvariantMonoidalTests[F[_]] extends InvariantSemigroupalTests[F] {
def laws: InvariantMonoidalLaws[F]
Expand All @@ -47,7 +48,7 @@ trait InvariantMonoidalTests[F[_]] extends InvariantSemigroupalTests[F] {
new RuleSet {
val name = "invariantMonoidal"
val parents = Seq(invariantSemigroupal[A, B, C])
val bases = Seq.empty
val bases: Seq[(String, Laws#RuleSet)] = Seq.empty
val props = Seq(
"invariant monoidal left identity" -> forAll((fa: F[A]) => laws.invariantMonoidalLeftIdentity(fa)),
"invariant monoidal right identity" -> forAll((fa: F[A]) => laws.invariantMonoidalRightIdentity(fa))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package discipline
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Cogen}
import org.typelevel.discipline.Laws

trait InvariantSemigroupalTests[F[_]] extends InvariantTests[F] with SemigroupalTests[F] {
def laws: InvariantSemigroupalLaws[F]
Expand All @@ -47,7 +48,7 @@ trait InvariantSemigroupalTests[F[_]] extends InvariantTests[F] with Semigroupal
new RuleSet {
val name = "invariantSemigroupal"
val parents = Seq(invariant[A, B, C], semigroupal[A, B, C])
val bases = Nil
val bases: Seq[(String, Laws#RuleSet)] = Nil
val props = Seq(
"invariant semigroupal associativity" -> forAll((fa: F[A], fb: F[B], fc: F[C]) =>
laws.invariantSemigroupalAssociativity(fa, fb, fc)
Expand Down
2 changes: 1 addition & 1 deletion tests/shared/src/test/scala/cats/tests/FoldableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ class FoldableIdTSuite extends FoldableSuite[IdT[Option, *]]("idT") {
}

class FoldableConstSuite extends FoldableSuite[Const[Int, *]]("const") {
def iterator[T](const: Const[Int, T]) = None.iterator
def iterator[T](const: Const[Int, T]): Iterator[T] = None.iterator
}

class FoldableTuple2Suite extends FoldableSuite[(Int, *)]("tuple2") {
Expand Down

0 comments on commit e0f0b40

Please sign in to comment.