diff options
Diffstat (limited to 'sources/scala/List.scala')
-rw-r--r-- | sources/scala/List.scala | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sources/scala/List.scala b/sources/scala/List.scala index 9459184829..135a998000 100644 --- a/sources/scala/List.scala +++ b/sources/scala/List.scala @@ -71,12 +71,14 @@ object List { Pair(f :: fs, s :: ss) } - /** Converts an array into a list. - * @param arr the array to convert - * @returns a list that contains the same elements than <code>arr</code> - * in the same order + /** Converts an iterator to a list + * @param it the iterator to convert + * @returns a list that contains the elements returned by successive + * calls to <code>it.next</code> */ - def fromArray[a](arr: Array[a]): List[a] = fromArray(arr, 0, arr.length); + def fromIterator[a](it: Iterator[a]): List[a] = + if (it.hasNext) it.next :: fromIterator(it); + else Nil; /** Converts a range of an array into a list. * @param arr the array to convert @@ -112,7 +114,7 @@ object List { start = end; end = str.indexOf(separator, end); } - res.reverse + res.reverse } } |