
28 Dec
2016
28 Dec
'16
2:54 a.m.
My goal is to take data like this: and build a Map like this:
you do not want to insert into the map but alter instead: numTopicsPerState :: M.Map String (M.Map String Integer) numTopicsPerState = foldl' addState M.empty [ Info 0 "Alcohol" "TX" , Info 1 "Alcohol" "TX" , Info 2 "Pregnancy" "MA" ] where addState accum currentRow = M.alter addTopic (state currentRow) accum where addTopic accum = Just $ M.alter incCount (healthTopic currentRow) (fromMaybe M.empty accum) incCount oldCount = Just $ 1 + fromMaybe 0 oldCount