एक ही तत्व n-times के साथ सूची कैसे बनाएं?एक ही तत्व n-times के साथ सूची कैसे बनाएं?
मैन्युअल implementnation:
scala> def times(n: Int, s: String) =
| (for(i <- 1 to n) yield s).toList
times: (n: Int, s: String)List[String]
scala> times(3, "foo")
res4: List[String] = List(foo, foo, foo)
वहाँ भी एक अंतर्निहित तरीका भी ऐसा ही करने है?
अधिक जानकारी के लिए GenTraversableFactory देखें, और इस पृष्ठ पर # 14: http://nicholassterling.wordpress.com/2012/01/28/scala-snippets/ – AmigoNico