Monday, November 9, 2009
Using objects as functions
A fun but easily overlooked fact is that many classes inherit from a Function class and therefore can be used where "normal" functions can be used.
- scala> List(1,2) map (Map(1->"one",2->"two"))
- res0: List[java.lang.String] = List(one, two)
- scala> List(3,3,2) map (List('a', 'b', 'c','d'))
- res2: List[Char] = List(d, d, c)
posted
11/09/2009
Labels:
function,
intermediate,
list,
Map,
Scala
Subscribe to:
Post Comments (Atom)
1 comment:
Nice trick. This works for Array and Set as well.
Reply DeleteNice blog btw!