- nil: {α : Type u} → {β : Type v} → Std.AssocList α β
An empty list
- cons: {α : Type u} → {β : Type v} → α → β → Std.AssocList α β → Std.AssocList α β
Add a
key, value
pair to the list
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.
Instances For
Equations
- Std.instInhabitedAssocList = { default := Std.AssocList.nil }
O(n)
. Convert an AssocList α β
into the equivalent List (α × β)
.
This is used to give specifications for all the AssocList
functions
in terms of corresponding list functions.
Equations
- Std.AssocList.toList Std.AssocList.nil = []
- Std.AssocList.toList (Std.AssocList.cons a b es) = (a, b) :: Std.AssocList.toList es
Instances For
Equations
- Std.AssocList.instEmptyCollectionAssocList = { emptyCollection := Std.AssocList.nil }
O(1)
. Is the list empty?
Equations
- Std.AssocList.isEmpty x = match x with | Std.AssocList.nil => true | x => false
Instances For
O(n)
. Fold a monadic function over the list, from head to tail.
Equations
- Std.AssocList.foldlM f x Std.AssocList.nil = pure x
- Std.AssocList.foldlM f x (Std.AssocList.cons a b es) = do let __do_lift ← f x a b Std.AssocList.foldlM f __do_lift es
Instances For
O(n)
. Fold a function over the list, from head to tail.
Equations
- Std.AssocList.foldl f init as = Id.run (Std.AssocList.foldlM f init as)
Instances For
Optimized version of toList
.
Equations
- Std.AssocList.toListTR as = Array.toList (Std.AssocList.foldl (fun r a b => Array.push r (a, b)) #[] as)
Instances For
O(n)
. Run monadic function f
on all elements in the list, from head to tail.
Equations
- Std.AssocList.forM f Std.AssocList.nil = pure PUnit.unit
- Std.AssocList.forM f (Std.AssocList.cons a b es) = do f a b Std.AssocList.forM f es
Instances For
O(n)
. Map a function f
over the keys of the list.
Equations
- Std.AssocList.mapKey f Std.AssocList.nil = Std.AssocList.nil
- Std.AssocList.mapKey f (Std.AssocList.cons a b es) = Std.AssocList.cons (f a) b (Std.AssocList.mapKey f es)
Instances For
O(n)
. Map a function f
over the values of the list.
Equations
- Std.AssocList.mapVal f Std.AssocList.nil = Std.AssocList.nil
- Std.AssocList.mapVal f (Std.AssocList.cons a b es) = Std.AssocList.cons a (f a b) (Std.AssocList.mapVal f es)
Instances For
O(n)
. Returns the first entry in the list whose entry satisfies p
.
Equations
- Std.AssocList.findEntryP? p Std.AssocList.nil = none
- Std.AssocList.findEntryP? p (Std.AssocList.cons a b es) = bif p a b then some (a, b) else Std.AssocList.findEntryP? p es
Instances For
O(n)
. Returns the first entry in the list whose key is equal to a
.
Equations
- Std.AssocList.findEntry? a l = Std.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
- Std.AssocList.find? a Std.AssocList.nil = none
- Std.AssocList.find? a (Std.AssocList.cons a_1 b es) = match a_1 == a with | true => some b | false => Std.AssocList.find? a es
Instances For
O(n)
. Returns true if any entry in the list satisfies p
.
Equations
- Std.AssocList.any p Std.AssocList.nil = false
- Std.AssocList.any p (Std.AssocList.cons a b es) = (p a b || Std.AssocList.any p es)
Instances For
O(n)
. Returns true if every entry in the list satisfies p
.
Equations
- Std.AssocList.all p Std.AssocList.nil = true
- Std.AssocList.all p (Std.AssocList.cons a b es) = (p a b && Std.AssocList.all p es)
Instances For
Returns true if every entry in the list satisfies p
.
Equations
- Std.AssocList.All p l = ((a : α × β) → a ∈ Std.AssocList.toList l → p a.fst a.snd)
Instances For
O(n)
. Returns true if there is an element in the list whose key is equal to a
.
Equations
- Std.AssocList.contains a l = Std.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
- Std.AssocList.replace a b Std.AssocList.nil = Std.AssocList.nil
- Std.AssocList.replace a b (Std.AssocList.cons a_1 b_1 es) = match a_1 == a with | true => Std.AssocList.cons a b es | false => Std.AssocList.cons a_1 b_1 (Std.AssocList.replace a b es)
Instances For
O(n)
. Remove the first entry in the list with key equal to a
.
Equations
- Std.AssocList.eraseP p Std.AssocList.nil = Std.AssocList.nil
- Std.AssocList.eraseP p (Std.AssocList.cons a b es) = bif p a b then es else Std.AssocList.cons a b (Std.AssocList.eraseP p es)
Instances For
O(n)
. Remove the first entry in the list with key equal to a
.
Equations
- Std.AssocList.erase a l = Std.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
- Std.AssocList.modify a f Std.AssocList.nil = Std.AssocList.nil
- Std.AssocList.modify a f (Std.AssocList.cons a_1 b es) = match a_1 == a with | true => Std.AssocList.cons a (f a_1 b) es | false => Std.AssocList.cons a_1 b (Std.AssocList.modify a f es)
Instances For
The implementation of ForIn
, which enables for (k, v) in aList do ...
notation.
Equations
- One or more equations did not get rendered due to their size.
- Std.AssocList.forIn Std.AssocList.nil init f = pure init
Instances For
Split the list into head and tail, if possible.
Equations
- Std.AssocList.pop? x = match x with | Std.AssocList.nil => none | Std.AssocList.cons a b l => some ((a, b), l)
Instances For
Equations
- Std.AssocList.instToStreamAssocList = { toStream := fun x => x }
Equations
- Std.AssocList.instStreamAssocListProd = { next? := Std.AssocList.pop? }
Converts a list into an AssocList
. This is the inverse function to AssocList.toList
.
Equations
- List.toAssocList [] = Std.AssocList.nil
- List.toAssocList ((a, b) :: es) = Std.AssocList.cons a b (List.toAssocList es)