fork download
  1. object Main extends App {
  2. def repeat [X] (x:X, n:Int) : List[X] = {
  3. if (n == 0)
  4. Nil
  5. x :: repeat (x, n - 1)
  6. }
  7.  
  8. val xs:List[(Char,Int)] = List (('a', 2), ('b', 4), ('c', 8))
  9.  
  10. val ys = xs.map ((p:(Char,Int)) => repeat (p._1, p._2))
  11.  
  12. val zs = xs.flatMap ((p:(Char,Int)) => repeat (p._1, p._2))
  13. }
Success #stdin #stdout 0.39s 322432KB
stdin
repeat(4,5)
stdout
Standard output is empty