I saw this thread:
What are the biggest differences between Scala 2.8 and Scala 2.7?
It seems to cover some changes, but the first compile problems I've hit don't seem to be mentioned. Any suggestions?
- kinds of the type arguments (Iterable[Any] with (A with Int) => Any) do not conform to the expected kinds of the type parameters (type CC) in class GenericCompanion. Iterable[Any] with (A with Int) => Any's type parameters do not match type CC's expected parameters: has no type parameters, but type CC has one
- object creation impossible, since method iterator in trait IterableLike of type => Iterator[java.io.File] is not defined
- object creation impossible, since method iterator in trait IterableLike of type => Iterator[V] is not defined
- overriding method elements in trait IterableLike of type => Iterator[java.io.File]; method elements needs `override' modifier
- overriding method elements in trait IterableLike of type => Iterator[V]; method elements needs `override' modifier
Here's the code in question:
/**
* Filesystem walker.
* <p>
* Less magic version of: http://rosettacode.org/wiki/Walk_Directory_Tree#Scala
*/
object FsWalker {
/**
* Recursive iterator over all files (and directories) in given directory.
*/
def walk(f: File): Iterable[File] = new Iterable[File] {
def elements = {
if (f.isDirectory()) {
// recurse on our child files
f.listFiles.elements.flatMap(child => FsWalker.walk(child).elements)
} else {
// just return given file wrapped in Iterator
Seq(f).elements
}
}
}
}
iterator
forelements
, your code compiles. – Benzoyl