Unique characters: Difference between revisions

→‎{{header|Haskell}}: Preferred Data.Map.Strict methods to a list comprehension
(→‎{{header|Haskell}}: Preferred Data.Map.Strict methods to a list comprehension)
Line 624:
 
uniqueChars :: [String] -> String
uniqueChars ws =
M.keys . M.filter (1 ==)
[ k
. foldr (M.unionWith (+) . charCounts) M.empty
| (k, v) <-
 
M.assocs $ foldr addedWord M.empty ws,
charCounts :: String -> M.Map Char Int
1 == v
charCounts =
]
wherefoldr
updatedCharCount c =(flip (M.insertWith (+) c) 1)
addedWord = flip $ foldr updatedCharCount
M.empty
updatedCharCount c = M.insertWith (+) c 1
 
--------------------------- TEST -------------------------
9,655

edits