Skip to content

Instantly share code, notes, and snippets.

@dorsev
Created December 1, 2018 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorsev/50043f683a72adf6d54155992cfe0994 to your computer and use it in GitHub Desktop.
Save dorsev/50043f683a72adf6d54155992cfe0994 to your computer and use it in GitHub Desktop.
trait Trackable[T] {
def trackValue(off: Long, item: T): Unit
}
trait Gauge {
def set(off: Long): Unit
}
implicit val trackableLong = new Trackable[AtomicLong] {
override def trackValue(off: Long, item: AtomicLong): Unit =
item.set(off)
}
implicit val trackableGauage = new Trackable[Gauge] {
override def trackValue(off: Long, item: Gauge): Unit = item.set(off)
}
val gauge: Gauge = ???
val counter: AtomicLong = ???
def offsetMonitor[A](monitor: A)(implicit trackable: Trackable[A]) =
trackable.trackValue(12, monitor)
offsetMonitor(gauge)
offsetMonitor(counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment