Logo

Programming-Idioms

History of Idiom 112 > diff from v6 to v7

Edit summary for version 7 by :
New Haskell implementation by user [JH]

Version 6

2016-01-09, 18:03:31

Version 7

2016-02-16, 18:11:06

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
Code
forM_ 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.