
28 Dec
2016
28 Dec
'16
8:55 a.m.
On Wed, Dec 28, 2016 at 9:28 AM, Cody Goodman wrote: My goal is to take data like this: [ Info 0 "Alcohol" "TX"
, Info 1 "Alcohol" "TX"
, Info 2 "Pregnancy" "MA"
] and build a Map like this: [("MA",[("Pregnancy",1)]),("TX",[("Alcohol",2)])] You can convert each individual record to a singleton map:
wrapRecord :: Info -> M.Map String (M.Map String Integer)
wrapRecord (Info _ state healthTopic) = M.singleton state (M.singleton
healthTopic 1)
and then union all these singletons:
numTopicsPerState = M.unionsWith (M.unionWith (+)) . map wrapRecord $ [Info
0 "Alcohol" "TX", Info 1 "Alcohol" "TX", Info 2 "Pregnancy" "MA"]