This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: None  |  size: 0.60 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. scala> val caps: Map[String, Int] = Map(("A", 1), ("B", 2))
  2. caps: Map[String,Int] = Map(A -> 1, B -> 2)
  3.  
  4. scala> val lower: Map[Int, String] = Map((1, "a"), (2, "b"))
  5. lower: Map[Int,String] = Map(1 -> a, 2 -> b)
  6.  
  7. scala> caps.flatMap {
  8.      | case (cap, idx) => Map((cap, lower(idx)))
  9.      | }
  10. res1: scala.collection.immutable.Map[String,String] = Map(A -> a, B -> b)
  11.        
  12. scala> caps mapValues lower
  13. res0: scala.collection.immutable.Map[String,String] = Map(A -> a, B -> b)
  14.        
  15. scala> val composed = caps andThen lower
  16. composed: PartialFunction[String,String] = <function1>
  17.  
  18. scala> composed("A")
  19. res1: String = a
clone this paste RAW Paste Data