Fix and re-apply formatter on all acceptance tests

Less noise, pretty tuples. Everyone's happy.
This commit is contained in:
KtorZ
2023-01-14 11:45:34 +01:00
parent 5b7147fc43
commit 8c19d4ec08
16 changed files with 152 additions and 107 deletions

View File

@@ -1,10 +1,10 @@
/// An opaque `Dict`. The type is opaque because the module maintains some
/// invariant, namely: there's only one occurence of a given key in the dictionnary.
pub opaque type Dict<key, value> {
inner: List<#(ByteArray, value)>,
inner: List<(ByteArray, value)>,
}
pub fn toList(self: Dict<ByteArray, value>){
pub fn toList(self: Dict<ByteArray, value>) {
self.inner
}
@@ -20,7 +20,7 @@ pub fn insert(
) -> Dict<key, value> {
Dict {
inner: do_insert_with(self.inner, k, v, fn(_, left, _right) { Some(left) })}
}
pub fn union_with(
@@ -32,33 +32,33 @@ pub fn union_with(
}
fn do_union_with(
left: List<#(ByteArray, value)>,
right: List<#(ByteArray, value)>,
left: List<(ByteArray, value)>,
right: List<(ByteArray, value)>,
with: fn(ByteArray, value, value) -> Option<value>,
) -> List<#(ByteArray, value)> {
) -> List<(ByteArray, value)> {
when left is {
[] -> right
[#(k, v), ..rest] ->
[(k, v), ..rest] ->
do_union_with(rest, do_insert_with(right, k, v, with), with)
}
}
fn do_insert_with(
self: List<#(ByteArray, value)>,
self: List<(ByteArray, value)>,
key k: ByteArray,
value v: value,
with: fn(ByteArray, value, value) -> Option<value>,
) -> List<#(ByteArray, value)> {
) -> List<(ByteArray, value)> {
when self is {
[] -> [#(k, v)]
[#(k2, v2), ..rest] ->
[] -> [(k, v)]
[(k2, v2), ..rest] ->
if k == k2 {
when with(k, v, v2) is {
Some(combined) -> [#(k, combined), ..rest]
Some(combined) -> [(k, combined), ..rest]
None -> rest
}
} else {
[#(k2, v2), ..do_insert_with(rest, k, v, with)]
[(k2, v2), ..do_insert_with(rest, k, v, with)]
}
}
}