From 9a38d18013dc0a4df8e218cb175e89a944589950 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Wed, 25 Dec 2024 08:32:31 +0700 Subject: [PATCH] Adapt to new context bound/given syntax https://docs.scala-lang.org/sips/sips/typeclasses-syntax.html --- core/src/main/scala/Iso.scala | 2 +- core/src/main/scala/Render.scala | 2 +- core/src/main/scala/newtypes.scala | 4 ++-- core/src/main/scala/zeros.scala | 28 ++++++++++++++-------------- lila/src/main/scala/Json.scala | 4 ++-- lila/src/main/scala/future.scala | 4 ++-- lila/src/main/scala/paginator.scala | 4 ++-- playJson/src/main/scala/Json.scala | 8 ++++---- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/core/src/main/scala/Iso.scala b/core/src/main/scala/Iso.scala index 253c352..6e64dae 100644 --- a/core/src/main/scala/Iso.scala +++ b/core/src/main/scala/Iso.scala @@ -17,7 +17,7 @@ object Iso: type BooleanIso[B] = Iso[Boolean, B] type DoubleIso[B] = Iso[Double, B] - given sameRuntime[A, B](using sr: SameRuntime[A, B], rs: SameRuntime[B, A]): Iso[A, B] with + given [A, B] => (sr: SameRuntime[A, B], rs: SameRuntime[B, A]) => Iso[A, B]: val from = sr.apply val to = rs.apply diff --git a/core/src/main/scala/Render.scala b/core/src/main/scala/Render.scala index d19ffb2..f32faf1 100644 --- a/core/src/main/scala/Render.scala +++ b/core/src/main/scala/Render.scala @@ -15,4 +15,4 @@ object Render: /* If we have Render, we have Show; * but not the other way around. */ - given [A](using Render[A]): cats.Show[A] = cats.Show.show(_.render) + given [A] => Render[A] => cats.Show[A] = cats.Show.show(_.render) diff --git a/core/src/main/scala/newtypes.scala b/core/src/main/scala/newtypes.scala index 11e14fb..3f645a8 100644 --- a/core/src/main/scala/newtypes.scala +++ b/core/src/main/scala/newtypes.scala @@ -61,7 +61,7 @@ object newtypes: given SameRuntime[Newtype, Impl] = raw(_) given SameRuntime[Impl, Newtype] = apply(_) // Avoiding a simple cast because Eq is @specialized, so there might be edge cases. - given (using eqi: Eq[Impl]): Eq[Newtype] = new: + given (eqi: Eq[Impl]) => Eq[Newtype] = new: override def eqv(x: Newtype, y: Newtype) = eqi.eqv(raw(x), raw(y)) extension (inline a: Newtype) @@ -143,4 +143,4 @@ object newtypes: inline def floatOrdering[T: FloatRuntime](using Ordering[Float]): Ordering[T] = sameOrdering[Float, T] inline def doubleOrdering[T: DoubleRuntime](using Ordering[Double]): Ordering[T] = sameOrdering[Double, T] - given [A](using sr: SameRuntime[Boolean, A]): Zero[A] = Zero(sr(false)) + given [A] => (sr: SameRuntime[Boolean, A]) => Zero[A] = Zero(sr(false)) diff --git a/core/src/main/scala/zeros.scala b/core/src/main/scala/zeros.scala index 0f6c1ed..f657660 100644 --- a/core/src/main/scala/zeros.scala +++ b/core/src/main/scala/zeros.scala @@ -5,44 +5,44 @@ import scala.collection.immutable.SeqMap object zeros: - given Zero[String] with + given Zero[String]: def zero = "" - given Zero[Boolean] with + given Zero[Boolean]: def zero = false - given Zero[Int] with + given Zero[Int]: def zero = 0 - given Zero[Long] with + given Zero[Long]: def zero = 0L - given Zero[Double] with + given Zero[Double]: def zero = 0d - given Zero[Float] with + given Zero[Float]: def zero = 0f - given Zero[Unit] with + given Zero[Unit]: def zero = () - given [A]: Zero[List[A]] with + given [A] => Zero[List[A]]: def zero = List.empty - given [A, B]: Zero[Map[A, B]] with + given [A, B] => Zero[Map[A, B]]: def zero = Map.empty - given [A]: Zero[Option[A]] with + given [A] => Zero[Option[A]]: def zero = Option.empty - given [A]: Zero[Set[A]] with + given [A] => Zero[Set[A]]: def zero = Set.empty - given [A]: Zero[Seq[A]] with + given [A] => Zero[Seq[A]]: def zero = Seq.empty - given [A]: Zero[Vector[A]] with + given [A] => Zero[Vector[A]]: def zero = Vector.empty - given [A, B]: Zero[SeqMap[A, B]] with + given [A, B] => Zero[SeqMap[A, B]]: def zero = SeqMap.empty diff --git a/lila/src/main/scala/Json.scala b/lila/src/main/scala/Json.scala index ce35b54..748bd14 100644 --- a/lila/src/main/scala/Json.scala +++ b/lila/src/main/scala/Json.scala @@ -9,10 +9,10 @@ object Json: export scalalib.json.Json.{ *, given } export scalalib.json.extensions.{ *, given } - given Writes[MaxPerPage] with + given Writes[MaxPerPage]: def writes(m: MaxPerPage) = JsNumber(m.value) - given paginatorWrite[A: Writes]: OWrites[Paginator[A]] = OWrites[Paginator[A]]: p => + given [A: Writes] => OWrites[Paginator[A]] = OWrites[Paginator[A]]: p => paginatorWriteNoNbResults.writes(p) ++ PlayJson.obj( "nbResults" -> p.nbResults, "nbPages" -> p.nbPages diff --git a/lila/src/main/scala/future.scala b/lila/src/main/scala/future.scala index 30a0fa5..1ebaf10 100644 --- a/lila/src/main/scala/future.scala +++ b/lila/src/main/scala/future.scala @@ -16,8 +16,8 @@ type FutureAfter = [T] => (FiniteDuration) => (() => Future[T]) => Future[T] final class TimeoutException(msg: String) extends Exception(msg) with NoStackTrace -given [A](using az: Zero[A]): Zero[Future[A]] with - def zero = Future.successful(az.zero) +given [A: Zero] => Zero[Future[A]]: + def zero = Future.successful(Zero[A].zero) object extensions: diff --git a/lila/src/main/scala/paginator.scala b/lila/src/main/scala/paginator.scala index 55f3ae9..6b917d8 100644 --- a/lila/src/main/scala/paginator.scala +++ b/lila/src/main/scala/paginator.scala @@ -63,10 +63,10 @@ object Paginator: def empty[A]: Paginator[A] = new Paginator(0, MaxPerPage(0), Nil, 0) - given [A]: Zero[Paginator[A]] with + given [A] => Zero[Paginator[A]]: def zero = empty[A] - given cats.Functor[Paginator] with + given cats.Functor[Paginator]: def map[A, B](p: Paginator[A])(f: A => B) = new Paginator( currentPage = p.currentPage, maxPerPage = p.maxPerPage, diff --git a/playJson/src/main/scala/Json.scala b/playJson/src/main/scala/Json.scala index 4d703cb..4ac69c8 100644 --- a/playJson/src/main/scala/Json.scala +++ b/playJson/src/main/scala/Json.scala @@ -13,17 +13,17 @@ object Json: trait NoJsonHandler[A] // don't create default JSON handlers for this type - given Zero[JsObject] with + given Zero[JsObject]: def zero = JsObject(Seq.empty) - given opaqueFormat[A, T](using + given [A, T] => ( bts: SameRuntime[A, T], stb: SameRuntime[T, A], format: Format[A] - )(using NotGiven[NoJsonHandler[T]]): Format[T] = + ) => NotGiven[NoJsonHandler[T]] => Format[T] = format.bimap(bts.apply, stb.apply) - given [A](using sr: SameRuntime[A, String]): KeyWrites[A] with + given [A] => (sr: SameRuntime[A, String]) => KeyWrites[A]: def writeKey(key: A) = sr(key) private val stringFormatBase: Format[String] = Format(Reads.StringReads, Writes.StringWrites)