Skip to content

Instantly share code, notes, and snippets.

@jdanbrown
Created March 3, 2014 21:00
Show Gist options
  • Save jdanbrown/9334525 to your computer and use it in GitHub Desktop.
Save jdanbrown/9334525 to your computer and use it in GitHub Desktop.
implicit class AnyOps[X](x: X) {
def withEffect (f: X => Unit) : X = { f(x); x }
def into[Y] (f: X => Y) : Y = f(x)
}
// Example usage:
def lifeTheUniverseAndEverything = 42 withEffect { x =>
log.debug("Someone asked 'the question' again, I told them %s", x)
meter("req.lifeTheUniverseAndEverything") += 1
}
def allTheThings: Iterator[String] = {
(0 until 100) map { i =>
"%s beers on the wall" format i
} into { xs =>
meter("beer.lines") += xs.size
xs.reverse.iterator
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment