Skip to content

Instantly share code, notes, and snippets.

@johnynek
Created November 26, 2013 23:30
Show Gist options
  • Select an option

  • Save johnynek/7668195 to your computer and use it in GitHub Desktop.

Select an option

Save johnynek/7668195 to your computer and use it in GitHub Desktop.
Idea for a metrics API for scalding and summingbird.
// basically the state monad on a Map[String, Long] where String is the name, long is the delta,
// and P is some platform specific type
trait Metric[P, T] {
def map[U](fn: T => U): Metric[P, U]
// monoid merge the metrics of the result with this:
def flatMap[U](fn: T => Metric[P, U]): Metric[P, U]
def increment(kv: (String, Long)): Metric[P, T] = for {
t <- this
_ <- Metric.increment(kv)
} yield t
def commit(implicit provider: MetricsProvider[P]): T
def deltas: Map[String, Long]
}
object Metric {
def pure[T](t: T): Metric[P, T]
def increment(kv: (String, Long)): Metric[P, Nothing]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment