Created
March 16, 2021 14:30
-
-
Save masakih/09e37f241947c816dbb7ead7904ca80c to your computer and use it in GitHub Desktop.
これ #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Reader: Sequence { | |
| struct Iterator: IteratorProtocol { | |
| func next() -> String? { | |
| readLine() | |
| } | |
| } | |
| func makeIterator() -> Iterator { | |
| .init() | |
| } | |
| } | |
| Reader() | |
| .flatMap { $0.split(separator: " ") } | |
| .map { $0.lowercased() } | |
| .reduce(into: [String: Int]()) { d, w in d[w, default: 0] += 1 } | |
| .sorted { $0.1 > $1.1 } | |
| .forEach { print($0.key, $0.value) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment