https://github.com/josephtlyons/counter
A counter for Gleam - modeled after Python's collections.Counter.
https://github.com/josephtlyons/counter
Last synced: about 2 months ago
JSON representation
A counter for Gleam - modeled after Python's collections.Counter.
- Host: GitHub
- URL: https://github.com/josephtlyons/counter
- Owner: JosephTLyons
- License: apache-2.0
- Created: 2024-06-28T21:37:32.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-01-13T09:45:54.000Z (5 months ago)
- Last Synced: 2025-04-22T16:18:38.083Z (about 2 months ago)
- Language: Gleam
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# counter
[](https://hex.pm/packages/counter)
[](https://hexdocs.pm/counter/)```sh
gleam add counter
```
```gleam
import counter
import gleam/iopub fn main() {
let c = ["dog", "cat", "mouse", "dog", "dog", "cat"] |> counter.from_listc |> counter.most_common |> io.debug
// [#("dog", 3), #("cat", 2), #("mouse", 1)]c |> counter.unique_size |> io.debug
// 3c |> counter.total |> io.debug
// 6c |> counter.get("horse") |> io.debug
// 0let c = c |> counter.insert("horse")
c |> counter.get("horse") |> io.debug
// 1c |> counter.keys |> io.debug
// ["cat", "dog", "horse", "mouse"]c |> counter.elements |> io.debug
// ["mouse", "horse", "dog", "dog", "dog", "cat", "cat"]
}
```