Logo

Programming-Idioms

History of Idiom 13 > diff from v43 to v44

Edit summary for version 44 by taktoa:
[Haskell] Original version was incorrect

Version 43

2016-02-18, 17:20:05

Version 44

2016-04-14, 15:09:17

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Imports
Imports
import Data.List (intercalate)
import qualified Data.Map as Map
Code
mapM_ print mymap
Code
let f _k _v = [show _k, " = ", show _x]
    mapped = Map.mapWithKeys f _mymap
in putStrLn $ intercalate "," $ mapped