score:1

foreach is, as ryan pointed out, solely for side-effects. it returns unit and not the list itself. ergo no chaining.

now what you are actually doing is the following:

val output = ranks.collect()
val realoutput: unit = output.foreach(tup => println(tup._1 + " has page rank: " + tup._2))
realoutput.saveastextfile(...)

saveastextfile is not a member of unit and you get your error message

you should be doing:

ranks.foreach(tup => println(tup._1 + " has page rank: " + tup._2))
ranks.saveastextfile(...)

or

ranks.saveastextfile(...)
ranks.collect().foreach(tup => println(tup._1 + " has page rank: " + tup._2))

Related Query

More Query from same tag