scala - count occurrences of elements -


this question has answer here:

counting elements in list one-liner in haskell:

count xs = tolist (fromlistwith (+) [(x, 1) | x <- xs]) 

here example usage:

*main> count "haskell scala" [(' ',1),('a',3),('c',1),('e',1),('h',1),('k',1),('l',3),('s',2)] 

can function expressed elegantly in scala well?

scala> "haskell scala".groupby(identity).mapvalues(_.size).toseq res1: seq[(char, int)] = arraybuffer((e,1), (s,2), (a,3), ( ,1), (l,3), (c,1), (h,1), (k,1)) 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -