何度も似たようなの書いては失くしちゃうので、メモ。 というか、標準のData.List.groupってあれ使い道あるのか? module Data.List.Missing where import Data.Maybe (fromMaybe) {- | 分類関数と加算器をつかってリストを集計する 分類のみ >>> groupBy' (`mod` 2) (flip (:)) [] [0..10] [(0,[10,8,6,4,2,0]),(1,[9,7,5,3,1])] 集計のみ >>> groupBy' id (\x _ -> x + 1) 0 [0,0,2,3,1,2,6] [(6,1),(2,2),(1,1),(3,1),(0,2)] 投票から得票数を求める例 >>> groupBy' snd (\x _ -> x + 1) 0 [(0,1),(1,0),(2,3),(3,0),(4,
![リストの分類と集計 - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/6e71637b82f6f721dc57b4abb42fc5b8582e0856/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-9f5428127621718a910c8b63951390ad.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTkxNiZoPTMzNiZ0eHQ9JUUzJTgzJUFBJUUzJTgyJUI5JUUzJTgzJTg4JUUzJTgxJUFFJUU1JTg4JTg2JUU5JUExJTlFJUUzJTgxJUE4JUU5JTlCJTg2JUU4JUE4JTg4JnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmdHh0LWNsaXA9ZWxsaXBzaXMmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz01MTRhYzMzZjc2MGM4ZWNhZDQ3OTg3Nzg2Y2EzM2JhNg%26mark-x%3D142%26mark-y%3D112%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTYxNiZ0eHQ9JTQwc2VhZ3VsbF9rYW1vbWUmdHh0LWNvbG9yPSUyMzIxMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT0zNiZ0eHQtYWxpZ249bGVmdCUyQ3RvcCZzPTViNTM2NWQzN2MwM2ZmMDE3Mjk2NGUxYzViMTVhOGU1%26blend-x%3D142%26blend-y%3D491%26blend-mode%3Dnormal%26s%3Deb77b11863afdc998f293c4b06f165a9)