Skip to content

Instantly share code, notes, and snippets.

View sageserpent-open's full-sized avatar
💭
Concentrating on trucking right.

Gerard Murphy sageserpent-open

💭
Concentrating on trucking right.
  • Seascale, England, United Kingdom
View GitHub Profile
@sageserpent-open
sageserpent-open / Unbounded.scala
Last active February 20, 2026 08:45
A lifted ordered type in Scala 2.13 that extends some underlying ordered type `X` with negative and positive infinities.
package com.sageserpent.gist
import scala.language.implicitConversions
object Unbounded {
implicit def ordering[X: Ordering]: Ordering[Unbounded[X]] =
(first: Unbounded[X], second: Unbounded[X]) =>
(first, second) match {
case (Finite(thisUnlifted), Finite(anotherUnlifted)) =>
Ordering[X].compare(thisUnlifted, anotherUnlifted)
case (PositiveInfinity, PositiveInfinity) => 0