Logo

Programming-Idioms

History of Idiom 112 > diff from v8 to v9

Edit summary for version 9 by :
[Haskell] original author mixed up forM_ with mapM_...

Version 8

2016-02-16, 19:13:24

Version 9

2016-02-17, 04:09:33

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Imports
import Data.Map as Map
Imports
import Data.Map as Map
Code
forM_ print (Map.toList mymap)
Code
mapM_ print (Map.toList mymap)
Comments bubble
Data.Map.Map is an ordered map, so Map.toList will give the elements in ascending order by key.
Comments bubble
Data.Map.Map is an ordered map, so Map.toList will give the elements in ascending order by key.