Decorate-sort-undecorate idiom: Difference between revisions
Content added Content deleted
m (fixing typos) |
|||
Line 226: | Line 226: | ||
[[File:Fōrmulæ - Decorate-sort-undecorate idiom 05.png]] |
[[File:Fōrmulæ - Decorate-sort-undecorate idiom 05.png]] |
||
=={{header|Haskell}}== |
|||
Haskell's standard sortOn is an implementation of this idiom. |
|||
<syntaxhighlight lang="haskell">import Data.List (sortOn) |
|||
main :: IO () |
|||
main = |
|||
mapM_ print $ |
|||
sortOn |
|||
snd |
|||
[ ("Rosetta", 7), |
|||
("Code", 4), |
|||
("is", 2), |
|||
("a", 1), |
|||
("programming", 11), |
|||
("chrestomathy", 12), |
|||
("site", 4) |
|||
]</syntaxhighlight> |
|||
{{Out}} |
|||
<pre>("a",1) |
|||
("is",2) |
|||
("Code",4) |
|||
("site",4) |
|||
("Rosetta",7) |
|||
("programming",11) |
|||
("chrestomathy",12)</pre> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |