Created
November 26, 2013 23:30
-
-
Save johnynek/7668195 to your computer and use it in GitHub Desktop.
Idea for a metrics API for scalding and summingbird.
This file contains hidden or 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
| // 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