counter
Types
Functions
pub fn add(
counter_1: Counter(a),
counter_2: Counter(a),
) -> Counter(a)
Add the counts from two Counter
s into a new Counter
.
pub fn elements(counter: Counter(a)) -> List(a)
Returns a non-unique list of all the items in the Counter
. Each item will be repeated in the list the number of times it was inserted into the Counter
.
pub fn from_dict(d: Dict(a, Int)) -> Counter(a)
Creates a Counter
from a gleam/dict
of item-count pairs.
pub fn from_list(items: List(a)) -> Counter(a)
Creates a Counter
from a list of items.
pub fn get(counter: Counter(a), item: a) -> Int
Returns the number of times an item has been inserted into the Counter
.
pub fn insert(counter: Counter(a), item: a) -> Counter(a)
Inserts an item into the Counter
.
pub fn keys(counter: Counter(a)) -> List(a)
Returns a list of all the unique items in the Counter
.
pub fn most_common(
counter: Counter(a),
n: Option(Int),
) -> List(#(a, Int))
Returns a list containing the item-count tuples, sorted by count in descending order.
If n
is None
, the entire list is returned. If n
is Some
, a list the top n
most-common items is returned.
pub fn subtract(
counter_1: Counter(a),
counter_2: Counter(a),
) -> Counter(a)
Subtracts the counts in the second Counter
from the first Counter
, returning a new Counter
with the results.
Only items present in both Counter
s will be used when subtracting counts from the first Counter
and any item with a count of zero or less will be omitted from the new Counter
.
pub fn to_dict(counter: Counter(a)) -> Dict(a, Int)
Returns the underlying gleam/dict
of the Counter
.
pub fn to_list(counter: Counter(a)) -> List(#(a, Int))
Returns a list of item-count tuples.
pub fn update(counter: Counter(a), items: List(a)) -> Counter(a)
Updates the Counter
from a list of items.