Associative array/Iteration: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: Slight applicative tidying, to foreground the 3 functions. Added output)
Line 1,188: Line 1,188:
<lang haskell>import qualified Data.Map as M
<lang haskell>import qualified Data.Map as M


myMap :: M.Map String Int
myMap = M.fromList [("hello", 13), ("world", 31), ("!", 71)]
myMap = M.fromList [("hello", 13), ("world", 31), ("!", 71)]


main = do -- pairs
main :: IO ()
main =
print $ M.toList myMap
(putStrLn . unlines) $
-- keys
print $ M.keys myMap
[ show . M.toList -- Pairs
-- values
, show . M.keys -- Keys
print $ M.elems myMap</lang>
, show . M.elems -- Values
] <*>
pure myMap</lang>
{{Out}}
<pre>[("!",71),("hello",13),("world",31)]
["!","hello","world"]
[71,13,31]</pre>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==