import Data.Map.Strict as Map
keyValuesToMap
:: (Eq k
, Ord k
, Ord v
) => [(k
, v
)] -> Map k
[v
]keyValuesToMap x = keyValuesToMap_ x empty
keyValuesToMap
_ :: (Eq k
, Ord k
, Ord v
) => [(k
, v
)] -> Map k
[v
] -> Map k
[v
]keyValuesToMap
_ (x:xs
) map = keyValuesToMap
_ xs map
_ where
(key, val) = x
currVal
= findWithDefault
[] key
map map
_ = insert key
(currVal
++ [val
]) map
main = do
print $ keyValuesToMap
[(1, "one"), (2, "two"), (1, "uno")]
aW1wb3J0IERhdGEuTWFwLlN0cmljdCBhcyBNYXAKCmtleVZhbHVlc1RvTWFwIDo6IChFcSBrLCBPcmQgaywgT3JkIHYpID0+IFsoaywgdildIC0+IE1hcCBrIFt2XQprZXlWYWx1ZXNUb01hcCB4ID0ga2V5VmFsdWVzVG9NYXBfIHggZW1wdHkKCmtleVZhbHVlc1RvTWFwXyA6OiAoRXEgaywgT3JkIGssIE9yZCB2KSA9PiBbKGssIHYpXSAtPiBNYXAgayBbdl0gLT4gTWFwIGsgW3ZdCmtleVZhbHVlc1RvTWFwXyBbXSBtYXAgPSBtYXAKa2V5VmFsdWVzVG9NYXBfICh4OnhzKSBtYXAgPSBrZXlWYWx1ZXNUb01hcF8geHMgbWFwXwogICAgd2hlcmUKICAgICAgICAoa2V5LCB2YWwpID0geAogICAgICAgIGN1cnJWYWwgPSBmaW5kV2l0aERlZmF1bHQgW10ga2V5IG1hcAogICAgICAgIG1hcF8gPSBpbnNlcnQga2V5IChjdXJyVmFsICsrIFt2YWxdKSBtYXAKCm1haW4gPSBkbwogICAgcHJpbnQgJCBrZXlWYWx1ZXNUb01hcCBbKDEsICJvbmUiKSwgKDIsICJ0d28iKSwgKDEsICJ1bm8iKV0=