Logo

Programming-Idioms

History of Idiom 13 > diff from v44 to v45

Edit summary for version 45 by taktoa:
[Haskell] Less confusing syntax

Version 44

2016-04-14, 15:09:17

Version 45

2016-04-14, 15:11:07

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
import Data.List (intercalate)
import qualified Data.Map as Map
Imports
import Data.List (intercalate)
import qualified Data.Map as Map
Code
let f _k _v = [show _k, " = ", show _x]
    mapped = Map.mapWithKeys f _mymap
in putStrLn $ intercalate "," $ mapped
Code
let f k v = [show k, " = ", show v]
    mapped = Map.mapWithKeys f mymap
in putStrLn $ intercalate "," $ mapped