Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New given syntax #75

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.3"
version = "3.8.4-RC4"
runner.dialect = scala3

align.preset = more
Expand Down
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
3 changes: 2 additions & 1 deletion lila/src/main/scala/HeapSort.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ object HeapSort:
* should be used for small nb and large n
* Complexity: O(n + nb * log(n))
*/
def topN[T, C](xs: IterableOnce[T], nb: Int)(using ord: Ordering[T])(using
def topN[T, C](xs: IterableOnce[T], nb: Int)(using
ord: Ordering[T],
bf: BuildFrom[xs.type, T, C]
): C =
val p = PriorityQueue.from(xs)(ord)
Expand Down
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
2 changes: 1 addition & 1 deletion lila/src/main/scala/StringOps.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scalalib

import java.text.Normalizer
import java.lang.Character.{ UnicodeBlock as Block }
import java.lang.Character.UnicodeBlock as Block

object StringOps:

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
3 changes: 1 addition & 2 deletions lila/src/test/scala/WMMatchingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class WMMatchingTest extends munit.FunSuite:
def checkScore(ans: (Int, Int)): Boolean = res == ans
assert(WMMatching(v, pairScore) match
case Success(l) => checkScore(score(l))
case Failure(_) => false
)
case Failure(_) => false)

test("create S-blossom and use it for augmentation"):
check0(Array((1, 2, 8), (1, 3, 9), (2, 3, 10), (3, 4, 7)), false, List(-1, 2, 1, 4, 3))
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
Loading