Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created July 24, 2011 08:22
Show Gist options
  • Save kmizu/1102405 to your computer and use it in GitHub Desktop.
Save kmizu/1102405 to your computer and use it in GitHub Desktop.
An example of context bounds.
def sum[T:Numeric](xs: List[T]): T = {
val ev = implicitly[Numeric[T]]
xs.foldLeft(ev.zero){(acc, e) => ev.plus(acc, e)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment