Я обернул правильный ответ на этот вопрос в функцию, которая может добавлять несколько ведущих нулей, но по умолчанию добавляет 1 ноль.
function zeroFill(nr, depth){
depth = (depth === undefined)? 1 : depth;
var zero = "0";
for (var i = 0; i < depth; ++i) {
zero += "0";
}
return (zero + nr).slice(-(depth + 1));
}
для работы только с числами и не более 2 цифр, это также подход:
function zeroFill(i) {
return (i < 10 ? '0' : '') + i
}
List.fromIterator expects a scala.Iterator but your implicit is returning a java.util.Iterator.
This works
import java.util.Enumeration
implicit def enum2Iterator[A](e : Enumeration[A]) = new Iterator[A] {
def next = e.nextElement
def hasNext = e.hasMoreElements
}
import java.util.zip.{ZipFile, ZipEntry}
val l = List.fromIterator(new ZipFile(null:java.io.File).entries)
Adding one import at the top prevents compilation
import java.util.Iterator
There's been some discussion about unifying Scala and Java in 2.8 by just using java.util.Iterator. On the downside, Java's Iterator has a remove method which makes no sense for Scala's immutable collections. UnsupportedOperationException? Blech! On the plus side that makes stuff like this error go away.
Edit: I've added a Trac issue that the error message would have been clearer had it said "required: scala.Iterator[?]" https://lampsvn.epfl.ch/trac/scala/ticket/2102
Насколько мне известно, Enumeration в Scala 2.7.x имеет метод «elements», а Scala 2.8.0 имеет метод «итератора», сохраняющий Iterator. Почему бы их не использовать?
Да ладно, ладно. Перечисление Java .