Created
July 31, 2018 12:06
-
-
Save portnov/6615d9636f91acce3417c7e9d7ab4622 to your computer and use it in GitHub Desktop.
Data.Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.Map as M | |
import qualified Data.Set as S | |
import Data.Monoid | |
type Classification = M.Map String String | |
type Value = Int | |
src :: M.Map Classification Value | |
src = | |
let key1 = M.fromList [("cls1", "v1"), ("cls2", "v2")] | |
key2 = M.fromList [("cls1", "v1"), ("cls2", "v3")] | |
key3 = M.fromList [("cls1", "v4"), ("cls2", "v2")] | |
in M.fromList [(key1, 5), (key2, 10), (key3, 7)] | |
main :: IO () | |
main = do | |
let keys = S.fromList ["cls1"] | |
let result = M.mapKeysWith (+) (\cls -> M.restrictKeys cls keys) src | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment