Created
December 1, 2018 21:51
-
-
Save dorsev/50043f683a72adf6d54155992cfe0994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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