diff options
author | Martin Odersky <odersky@gmail.com> | 2009-02-05 19:25:43 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-02-05 19:25:43 +0000 |
commit | 0ecacced0347e4e3b83989a274b9de53868a3a57 (patch) | |
tree | cf5bb351b3acef82ad88862bee320b9c6e32a4c3 /src/library/scalax/collection/generic/IterableFactory.scala | |
parent | 48355ee28a930f19000901d761f24ca44b324c1f (diff) | |
download | scala-0ecacced0347e4e3b83989a274b9de53868a3a57.tar.gz scala-0ecacced0347e4e3b83989a274b9de53868a3a57.tar.bz2 scala-0ecacced0347e4e3b83989a274b9de53868a3a57.zip |
added support for Strings, arrays, sets.
Diffstat (limited to 'src/library/scalax/collection/generic/IterableFactory.scala')
-rwxr-xr-x | src/library/scalax/collection/generic/IterableFactory.scala | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/library/scalax/collection/generic/IterableFactory.scala b/src/library/scalax/collection/generic/IterableFactory.scala index 1362e97079..9570970abe 100755 --- a/src/library/scalax/collection/generic/IterableFactory.scala +++ b/src/library/scalax/collection/generic/IterableFactory.scala @@ -26,7 +26,7 @@ trait IterableFactory[CC[A] <: Iterable[A]] { * @param n The number of elements returned * @param elem The element returned each time */ - def fill[A](n: Int, elem: => A): CC[A] = { + def fill[A](n: Int)(elem: => A): CC[A] = { val b = newBuilder[A] var i = 0 while (i < n) { @@ -36,11 +36,17 @@ trait IterableFactory[CC[A] <: Iterable[A]] { b.result } - def fill[A](n1: Int, n2: Int, elem: => A): CC[CC[A]] = - tabulate(n1)(_ => fill(n2, elem)) + def fill[A](n1: Int, n2: Int)(elem: => A): CC[CC[A]] = + tabulate(n1)(_ => fill(n2)(elem)) - def fill[A](n1: Int, n2: Int, n3: Int, elem: => A): CC[CC[CC[A]]] = - tabulate(n1)(_ => fill(n2, n3, elem)) + def fill[A](n1: Int, n2: Int, n3: Int)(elem: => A): CC[CC[CC[A]]] = + tabulate(n1)(_ => fill(n2, n3)(elem)) + + def fill[A](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => A): CC[CC[CC[CC[A]]]] = + tabulate(n1)(_ => fill(n2, n3, n4)(elem)) + + def fill[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => A): CC[CC[CC[CC[CC[A]]]]] = + tabulate(n1)(_ => fill(n2, n3, n4, n5)(elem)) def tabulate[A](n: Int)(f: Int => A): CC[A] = { val b = newBuilder[A] @@ -53,11 +59,16 @@ trait IterableFactory[CC[A] <: Iterable[A]] { } def tabulate[A](n1: Int, n2: Int)(f: (Int, Int) => A): CC[CC[A]] = - tabulate(n1)(i1 => tabulate(n2)(i2 => f(i1, i2))) + tabulate(n1)(i1 => tabulate(n2)(f(i1, _))) def tabulate[A](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => A): CC[CC[CC[A]]] = - tabulate(n1)(i1 => tabulate(n2)(i2 => tabulate(n3)(i3 => f(i1, i2, i3)))) -// todo: go up to 5(?) + tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _))) + + def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => A): CC[CC[CC[CC[A]]]] = + tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _))) + + def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => A): CC[CC[CC[CC[CC[A]]]]] = + tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _))) /** Create a sequence of increasing integers in a range. * |