Friday, 15 March 2013

error during reading number of lines in files using futures in scala -



error during reading number of lines in files using futures in scala -

object futures4 extends app { // array of files in directory tree def recursivelistfiles(f: file): array[file] = { val these = f.listfiles these ++ these.filter(_.isdirectory).flatmap(recursivelistfiles) } val files = recursivelistfiles(new java.io.file("path")) // convert list of total file paths val filenames = files.tolist map (_.getabsolutepath) println(filenames) val n: int = filenames.length val futures = { <- 0 n-1 } yield future { line_num(i) } // read file line def line_num(i: int) : int = { { line <- source.fromfile(filenames(i)).getlines //here getting multiple errors saying type mismatch }yield line.length } val sumf = future.fold(futures)(0)(_ + _) val sum = await.result(sumf, 2 seconds) println(sum) }

i want calculate number of lines in files present. new scala programming help appreciated! getting multiple errors @ 1 step have mentioned comment. thanks

line_num(i) returns number of lines in file i. can write it:

def line_num(i: int) : int = { source.fromfile(filenames(i)).getlines.size }

in original function, homecoming seq(int) sequence of length of each line in file, not correspond expected homecoming type.

file scala future scala-collections

No comments:

Post a Comment