Skip to content

Instantly share code, notes, and snippets.

@larsrh
Created August 30, 2012 20:31
Show Gist options
  • Save larsrh/3540130 to your computer and use it in GitHub Desktop.
Save larsrh/3540130 to your computer and use it in GitHub Desktop.
map as function
// <http://stackoverflow.com/q/12204869>
def map[T, U, X, CC[X] <: Traversable[X]](cct: CC[T], f: T => U)(implicit cbf: CanBuildFrom[CC[T], U, CC[U]]): CC[U] =
cct.map(t => f(t))(collection.breakOut(cbf))
/*
scala> map(List(1,2,3), (x: Int) => x.toString)
res1: List[java.lang.String] = List(1, 2, 3)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment