AssocList α β is "the same as" List (α × β), but flattening the structure
leads to one fewer pointer indirection (in the current code generator).
It is mainly intended as a component of HashMap, but it can also be used as a plain
key-value map.
- nil
{α : Type u}
{β : Type v}
: AssocList α β
An empty list
- cons
{α : Type u}
{β : Type v}
(key : α)
(value : β)
(tail : AssocList α β)
: AssocList α β
Add a
key, valuepair to the list
Instances For
Equations
Instances For
Equations
- Batteries.AssocList.instEmptyCollection = { emptyCollection := Batteries.AssocList.nil }
O(1). Is the list empty?
Instances For
The number of entries in an AssocList.
Equations
- Batteries.AssocList.nil.length = 0
- (Batteries.AssocList.cons a b es).length = es.length + 1
Instances For
O(n). Fold a monadic function over the list, from head to tail.
Equations
- Batteries.AssocList.foldlM f x✝ Batteries.AssocList.nil = pure x✝
- Batteries.AssocList.foldlM f x✝ (Batteries.AssocList.cons a b es) = do let __do_lift ← f x✝ a b Batteries.AssocList.foldlM f __do_lift es
Instances For
O(n). Fold a function over the list, from head to tail.
Equations
- Batteries.AssocList.foldl f init as = (Batteries.AssocList.foldlM (fun (d : δ) (a : α) (b : β) => pure (f d a b)) init as).run
Instances For
O(n). Run monadic function f on all elements in the list, from head to tail.
Equations
- Batteries.AssocList.forM f Batteries.AssocList.nil = pure PUnit.unit
- Batteries.AssocList.forM f (Batteries.AssocList.cons a b es) = do f a b Batteries.AssocList.forM f es
Instances For
O(n). Map a function f over the keys of the list.
Equations
Instances For
O(n). Map a function f over the values of the list.
Equations
Instances For
O(n). Returns the first entry in the list whose entry satisfies p.
Equations
- Batteries.AssocList.findEntryP? p Batteries.AssocList.nil = none
- Batteries.AssocList.findEntryP? p (Batteries.AssocList.cons a b es) = bif p a b then some (a, b) else Batteries.AssocList.findEntryP? p es
Instances For
O(n). Returns the first entry in the list whose key is equal to a.
Equations
- Batteries.AssocList.findEntry? a l = Batteries.AssocList.findEntryP? (fun (k : α) (x : β) => k == a) l
Instances For
O(n). Returns the first value in the list whose key is equal to a.
Equations
- Batteries.AssocList.find? a Batteries.AssocList.nil = none
- Batteries.AssocList.find? a (Batteries.AssocList.cons a_1 b es) = match a_1 == a with | true => some b | false => Batteries.AssocList.find? a es
Instances For
O(n). Returns true if any entry in the list satisfies p.
Equations
- Batteries.AssocList.any p Batteries.AssocList.nil = false
- Batteries.AssocList.any p (Batteries.AssocList.cons a b es) = (p a b || Batteries.AssocList.any p es)
Instances For
O(n). Returns true if every entry in the list satisfies p.
Equations
- Batteries.AssocList.all p Batteries.AssocList.nil = true
- Batteries.AssocList.all p (Batteries.AssocList.cons a b es) = (p a b && Batteries.AssocList.all p es)
Instances For
Returns true if every entry in the list satisfies p.
Instances For
O(n). Returns true if there is an element in the list whose key is equal to a.
Equations
- Batteries.AssocList.contains a l = Batteries.AssocList.any (fun (k : α) (x : β) => k == a) l
Instances For
O(n). Replace the first entry in the list
with key equal to a to have key a and value b.
Equations
- One or more equations did not get rendered due to their size.
- Batteries.AssocList.replace a b Batteries.AssocList.nil = Batteries.AssocList.nil
Instances For
O(n). Remove the first entry in the list with key equal to a.
Equations
- Batteries.AssocList.eraseP p Batteries.AssocList.nil = Batteries.AssocList.nil
- Batteries.AssocList.eraseP p (Batteries.AssocList.cons a b es) = bif p a b then es else Batteries.AssocList.cons a b (Batteries.AssocList.eraseP p es)
Instances For
O(n). Remove the first entry in the list with key equal to a.
Equations
- Batteries.AssocList.erase a l = Batteries.AssocList.eraseP (fun (k : α) (x : β) => k == a) l
Instances For
O(n). Replace the first entry a', b in the list
with key equal to a to have key a and value f a' b.
Equations
- One or more equations did not get rendered due to their size.
- Batteries.AssocList.modify a f Batteries.AssocList.nil = Batteries.AssocList.nil
Instances For
The implementation of ForIn, which enables for (k, v) in aList do ... notation.
Equations
- Batteries.AssocList.nil.forIn init f = pure init
- (Batteries.AssocList.cons a b es).forIn init f = do let __do_lift ← f (a, b) init match __do_lift with | ForInStep.done d => pure d | ForInStep.yield d => es.forIn d f
Instances For
Equations
- Batteries.AssocList.instForInProdOfMonad = { forIn := fun {β_1 : Type ?u.25} => Batteries.AssocList.forIn }
Equations
- Batteries.AssocList.instToStream = { toStream := fun (x : Batteries.AssocList α β) => x }
Equations
Converts a list into an AssocList. This is the inverse function to AssocList.toList.
Equations
- [].toAssocList = Batteries.AssocList.nil
- ((a, b) :: es).toAssocList = Batteries.AssocList.cons a b es.toAssocList
Instances For
Implementation of == on AssocList.
Equations
- Batteries.AssocList.nil.beq Batteries.AssocList.nil = true
- (Batteries.AssocList.cons key value tail).beq Batteries.AssocList.nil = false
- Batteries.AssocList.nil.beq (Batteries.AssocList.cons key value tail) = false
- (Batteries.AssocList.cons a b t).beq (Batteries.AssocList.cons a' b' t') = (a == a' && b == b' && t.beq t')