val wordMap = wordMap + (token,currentCount)
. , wordMap var,
wordMap = wordMap + (token,currentCount)
?:
io.Source.fromFile("textfile.txt")
.getLines.flatMap{ line =>
line.split("\\s+")
.groupBy(identity).mapValues(_.size)
}
.toStream
.groupBy(_._1).mapValues(_.map(_._2).sum)
.toList
, , . .
, ( ), Scala , Hadoop ( Hadoop Scala, Scrunch Scoobi).
EDIT: :
, flatMap. :
val line = "a b c b"
val tokens = line.split("\\s+")
identity is a function that just returns its argument, so if we groupBy (identity) `, :
val grouped = tokens.groupBy(identity)
, , :
val counts = grouped.mapValues(_.size)
, .
, flatMap? , , .
, :
a b c b
b c d d d
e f c
:
val countsByLine =
io.Source.fromFile("textfile.txt")
.getLines.flatMap{ line =>
line.split("\\s+")
.groupBy(identity).mapValues(_.size)
}
println(countsByLine.toList)
, . countsByLine Iterator, groupBy. Stream, . , , . groupBy .
val groupedCounts = countsByLine.toStream.groupBy(_._1)
println(groupedCounts.mapValues(_.toList))
, , , () :
val totalCounts = groupedCounts.mapValues(_.map(_._2).sum)
println(totalCounts.toList)
List((e,1), (f,1), (a,1), (b,3), (c,3), (d,3))
.