Skip to content

Commit

Permalink
🎨 remove explicit summons
Browse files Browse the repository at this point in the history
  • Loading branch information
twentylemon committed Dec 23, 2024
1 parent 28ca32f commit 1a1a27a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/org/lemon/advent/lib/graph/fill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def fill[N](adjacency: N => Seq[N], start: N): Set[N] =
* @tparam D the distance type
*/
def distanceFrom[N, D: Numeric](adjacency: N => Seq[(N, D)], end: N): Map[N, D] =
val distances = mutable.Map(end -> summon[Numeric[D]].zero)
val distances = mutable.Map(end -> Numeric[D].zero)
given Ordering[(N, D)] = Ordering.by[(N, D), D](_._2)
val queue = mutable.PriorityQueue(distances.head)

Expand Down Expand Up @@ -67,7 +67,7 @@ def distanceFrom[N](adjacency: N => Seq[N], end: N): Map[N, Int] =
*/
def allPaths[N, D: Numeric](adjacency: N => Seq[(N, D)], start: N, ends: N => Boolean): Set[Path[N, D]] =
val paths = mutable.Set.empty[Path[N, D]]
val queue = mutable.Queue(Path(path = Vector(start), distance = summon[Numeric[D]].zero))
val queue = mutable.Queue(Path(path = Vector(start), distance = Numeric[D].zero))

while queue.nonEmpty do
val node @ Path(path, distance) = queue.dequeue
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/lemon/advent/lib/graph/search.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.math.Ordering.Implicits._
*/
def pathFind[N, D: Numeric](adjacency: N => Seq[(N, D)], start: N, ends: N => Boolean): Option[Path[N, D]] =
given Ordering[Path[N, D]] = Ordering.by[Path[N, D], D](_.distance).reverse
val queue = mutable.PriorityQueue(Path(path = Vector(start), distance = summon[Numeric[D]].zero))
val queue = mutable.PriorityQueue(Path(path = Vector(start), distance = Numeric[D].zero))
val visited = mutable.Set(start)

while !queue.isEmpty && !ends(queue.head.at) do
Expand All @@ -38,8 +38,8 @@ def pathFind[N, D: Numeric](adjacency: N => Seq[(N, D)], start: N, ends: N => Bo
*/
def allShortestPaths[N, D: Numeric](adjacency: N => Seq[(N, D)], start: N, ends: N => Boolean): Set[Path[N, D]] =
val paths = mutable.Set.empty[Path[N, D]]
val queue = mutable.Queue(Path(path = Vector(start), distance = summon[Numeric[D]].zero))
val costs = mutable.Map(start -> summon[Numeric[D]].zero)
val queue = mutable.Queue(Path(path = Vector(start), distance = Numeric[D].zero))
val costs = mutable.Map(start -> Numeric[D].zero)

while !queue.isEmpty do
val node @ Path(path, distance) = queue.dequeue
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/lemon/advent/lib/parse/Num.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import scala.math.BigInt
/** Generic extractor object for parsing numbers.
*/
object Num:
def unapply[T: Numeric](s: String): Option[T] = summon[Numeric[T]].parseString(s)
def unapply[T: Numeric](s: String): Option[T] = Numeric[T].parseString(s)

0 comments on commit 1a1a27a

Please sign in to comment.