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 |
main :: IO () |
||
main = |
|||
print $ M.toList myMap |
|||
(putStrLn . unlines) $ |
|||
-- keys |
|||
[ show . M.toList -- Pairs |
|||
-- |
, show . M.keys -- Keys |
||
, 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}}== |