同じ要素でn回リストを作成するにはどうすればよいですか?同じ要素をn回使ってリストを作成するには?
手動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