Trying to generate, from a list of chars, a list of unique chars mapped to their frequency - e.g. something like:
List('a','b','a') -> List(('a',2), ('b',1))
So, just mucking around in the console, this works:
val l = List('a', 'b', 'c', 'b', 'c', 'a')
val s = l.toSet
s.map(i => (i, l.filter(x => x == i).size))
but, shortening by just combining the last 2 lines doesn't?
l.toSet.map(i => (i, l.filter(x => x == i).size))
gives the error "missing parameter type".
Can someone explain why Scala complains about this syntax?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…