I first need to say that I am quite new to Scala's collections' map reduce kind of functions.
What I am trying to do is counting for each row of a matrix, how many times (all) the elements of a list (in this case numbers from 0 to n) appear. The ideal output would be a matrix with the same number of rows of the input matrix and as many columns as the length of the list.
val list = List(0,1,2)
val matrix = Array(
1 1 2
3 1 0
2 0 2
val counts = matrix.map(r => r.map(x => (x,r.count(_ == x))).groupBy(_._1))
For each row
matrix, map each item
list into the number of its occurrences in
matrix.map(r => list.map(i => r.count(_ == i)))