Skip to content

Commit

Permalink
Adapt to new context bound/given syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Dec 28, 2024
1 parent 4bcabc5 commit 9a38d18
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/Iso.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/Render.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions core/src/main/scala/newtypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
28 changes: 14 additions & 14 deletions core/src/main/scala/zeros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lila/src/main/scala/Json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lila/src/main/scala/future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions lila/src/main/scala/paginator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions playJson/src/main/scala/Json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9a38d18

Please sign in to comment.