author | wenzelm |
Fri, 03 Aug 2018 15:29:11 +0200 | |
changeset 68715 | 8197c2857267 |
parent 68714 | 1d5ab386eaf0 |
child 68716 | 040c6298850b |
--- a/src/Pure/library.scala Fri Aug 03 15:04:24 2018 +0200 +++ b/src/Pure/library.scala Fri Aug 03 15:29:11 2018 +0200 @@ -259,6 +259,15 @@ result.toList } + def replicate[A](n: Int, a: A): List[A] = + if (n < 0) throw new IllegalArgumentException + else if (n == 0) Nil + else { + val res = new mutable.ListBuffer[A] + (1 to n).foreach(_ => res += a) + res.toList + } + /* proper values */