An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

# counter

[![Package Version](https://img.shields.io/hexpm/v/counter)](https://hex.pm/packages/counter)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/counter/)

```sh
gleam add counter
```
```gleam
import counter
import gleam/io

pub fn main() {
let c = ["dog", "cat", "mouse", "dog", "dog", "cat"] |> counter.from_list

c |> counter.most_common |> io.debug
// [#("dog", 3), #("cat", 2), #("mouse", 1)]

c |> counter.unique_size |> io.debug
// 3

c |> counter.total |> io.debug
// 6

c |> counter.get("horse") |> io.debug
// 0

let c = c |> counter.insert("horse")

c |> counter.get("horse") |> io.debug
// 1

c |> counter.keys |> io.debug
// ["cat", "dog", "horse", "mouse"]

c |> counter.elements |> io.debug
// ["mouse", "horse", "dog", "dog", "dog", "cat", "cat"]
}
```