Fix and re-apply formatter on all acceptance tests
Less noise, pretty tuples. Everyone's happy.
This commit is contained in:
@@ -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)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,18 +30,19 @@ pub fn add(left v0: Value, right v1: Value) -> Value {
|
||||
v0,
|
||||
v1,
|
||||
fn(_, a0, a1) {
|
||||
let asset = dict.union_with(
|
||||
a0,
|
||||
a1,
|
||||
fn(_, q0, q1) {
|
||||
let q = q0 + q1
|
||||
if q == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(q)
|
||||
}
|
||||
},
|
||||
)
|
||||
let asset =
|
||||
dict.union_with(
|
||||
a0,
|
||||
a1,
|
||||
fn(_, q0, q1) {
|
||||
let q = q0 + q1
|
||||
if q == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(q)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
when dict.toList(asset) is {
|
||||
[] -> None
|
||||
|
||||
Reference in New Issue
Block a user