Skip to content

Commit

Permalink
formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Apr 29, 2024
1 parent fa6cf16 commit 3cfd527
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 124 deletions.
6 changes: 3 additions & 3 deletions lib/aiken/cbor.ak
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test serialise_8() {
}

test serialise_9() {
serialise([Pair(1,#"ff")]) == #"a10141ff"
serialise([Pair(1, #"ff")]) == #"a10141ff"
}

/// Obtain a String representation of _anything_. This is particularly (and only) useful for tracing
Expand Down Expand Up @@ -115,7 +115,7 @@ fn do_diagnostic(self: Data, builder: ByteArray) -> ByteArray {
self,
{
// -------- Constr
let Pair(constr,fields) = un_constr_data(self)
let Pair(constr, fields) = un_constr_data(self)

// NOTE: This is fundamentally the same logic for serializing list. However, the compiler
// doesn't support mutual recursion just yet, so we can't extract that logic in a separate
Expand Down Expand Up @@ -292,7 +292,7 @@ test diagnostic_7() {
}

test diagnostic_7_alt() {
diagnostic([Pair(1,#"ff")]) == @"{_ 1: h'FF' }"
diagnostic([Pair(1, #"ff")]) == @"{_ 1: h'FF' }"
}

test diagnostic_8() {
Expand Down
146 changes: 74 additions & 72 deletions lib/aiken/dict.ak
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ fn do_delete(
when self is {
[] ->
[]
[Pair(k2,v2), ..rest] ->
[Pair(k2, v2), ..rest] ->
if builtin.less_than_equals_bytearray(k, k2) {
if k == k2 {
rest
} else {
self
}
} else {
[Pair(k2,v2), ..do_delete(rest, k)]
[Pair(k2, v2), ..do_delete(rest, k)]
}
}
}
Expand Down Expand Up @@ -157,9 +157,9 @@ fn do_filter(
when self is {
[] ->
[]
[Pair(k,v), ..rest] ->
[Pair(k, v), ..rest] ->
if with(k, v) {
[Pair(k,v), ..do_filter(rest, with)]
[Pair(k, v), ..do_filter(rest, with)]
} else {
do_filter(rest, with)
}
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn find(self: Dict<key, value>, value v: value) -> Option<ByteArray> {
fn do_find(self: Map<ByteArray, value>, value v: value) -> Option<ByteArray> {
when self is {
[] -> None
[Pair(k2,v2), ..rest] ->
[Pair(k2, v2), ..rest] ->
if v == v2 {
Some(k2)
} else {
Expand Down Expand Up @@ -270,7 +270,7 @@ fn do_foldr(
) -> result {
when self is {
[] -> zero
[Pair(k,v), ..rest] -> with(k, v, do_foldr(rest, zero, with))
[Pair(k, v), ..rest] -> with(k, v, do_foldr(rest, zero, with))
}
}

Expand Down Expand Up @@ -310,7 +310,7 @@ fn do_foldl(
) -> result {
when self is {
[] -> zero
[Pair(k,v), ..rest] -> do_foldl(rest, with(k, v, zero), with)
[Pair(k, v), ..rest] -> do_foldl(rest, with(k, v, zero), with)
}
}

Expand Down Expand Up @@ -342,7 +342,7 @@ fn do_from_map(xs: Map<ByteArray, value>) -> Map<ByteArray, value> {
when xs is {
[] ->
[]
[Pair(k,v), ..rest] -> do_insert(do_from_map(rest), k, v)
[Pair(k, v), ..rest] -> do_insert(do_from_map(rest), k, v)
}
}

Expand All @@ -351,39 +351,39 @@ test from_map_1() {
}

test from_map_2() {
from_map([Pair(foo,42), Pair(bar,14)]) == from_map(
[Pair(bar,14), Pair(foo,42)],
from_map([Pair(foo, 42), Pair(bar, 14)]) == from_map(
[Pair(bar, 14), Pair(foo, 42)],
)
}

test from_map_3() {
from_map([Pair(foo,42), Pair(bar,14)]) == fixture_1()
from_map([Pair(foo, 42), Pair(bar, 14)]) == fixture_1()
}

test from_map_4() {
from_map([Pair(foo,42), Pair(bar,14), Pair(foo,1337)]) == fixture_1()
from_map([Pair(foo, 42), Pair(bar, 14), Pair(foo, 1337)]) == fixture_1()
}

test bench_from_map() {
let dict =
from_map(
[
Pair("bbba",8),
Pair("bbab",12),
Pair("aabb",13),
Pair("aaab",9),
Pair("bbbb",16),
Pair("aaaa",1),
Pair("aaba",5),
Pair("abab",10),
Pair("baba",7),
Pair("baab",11),
Pair("abaa",2),
Pair("baaa",3),
Pair("bbaa",4),
Pair("babb",15),
Pair("abbb",14),
Pair("abba",6),
Pair("bbba", 8),
Pair("bbab", 12),
Pair("aabb", 13),
Pair("aaab", 9),
Pair("bbbb", 16),
Pair("aaaa", 1),
Pair("aaba", 5),
Pair("abab", 10),
Pair("baba", 7),
Pair("baab", 11),
Pair("abaa", 2),
Pair("baaa", 3),
Pair("bbaa", 4),
Pair("babb", 15),
Pair("abbb", 14),
Pair("abba", 6),
],
)

Expand Down Expand Up @@ -417,7 +417,7 @@ fn check_ascending_map(xs: Map<ByteArray, value>) {
when xs is {
[] -> Void
[_] -> Void
[Pair(x0,_), Pair(x1,_) as e, ..rest] ->
[Pair(x0, _), Pair(x1, _) as e, ..rest] ->
if builtin.less_than_bytearray(x0, x1) {
check_ascending_map([e, ..rest])
} else {
Expand All @@ -440,13 +440,13 @@ fn check_ascending_map_with(
) {
when xs is {
[] -> Void
[Pair(_,v)] ->
[Pair(_, v)] ->
if value_predicate(v) {
Void
} else {
fail @"value doesn't satisfy predicate"
}
[Pair(x0,v0), Pair(x1,_) as e, ..rest] ->
[Pair(x0, v0), Pair(x1, _) as e, ..rest] ->
if builtin.less_than_bytearray(x0, x1) {
if value_predicate(v0) {
check_ascending_map_with([e, ..rest], value_predicate)
Expand All @@ -463,22 +463,22 @@ test bench_from_ascending_map() {
let dict =
from_ascending_map(
[
Pair("aaaa",1),
Pair("aaab",9),
Pair("aaba",5),
Pair("aabb",13),
Pair("abaa",2),
Pair("abab",10),
Pair("abba",6),
Pair("abbb",14),
Pair("baaa",3),
Pair("baab",11),
Pair("baba",7),
Pair("babb",15),
Pair("bbaa",4),
Pair("bbab",12),
Pair("bbba",8),
Pair("bbbb",16),
Pair("aaaa", 1),
Pair("aaab", 9),
Pair("aaba", 5),
Pair("aabb", 13),
Pair("abaa", 2),
Pair("abab", 10),
Pair("abba", 6),
Pair("abbb", 14),
Pair("baaa", 3),
Pair("baab", 11),
Pair("baba", 7),
Pair("babb", 15),
Pair("bbaa", 4),
Pair("bbab", 12),
Pair("bbba", 8),
Pair("bbbb", 16),
],
)

Expand All @@ -502,7 +502,7 @@ pub fn get(self: Dict<key, value>, key: ByteArray) -> Option<value> {
fn do_get(self: Map<ByteArray, value>, key k: ByteArray) -> Option<value> {
when self is {
[] -> None
[Pair(k2,v), ..rest] ->
[Pair(k2, v), ..rest] ->
if builtin.less_than_equals_bytearray(k, k2) {
if k == k2 {
Some(v)
Expand Down Expand Up @@ -586,7 +586,7 @@ pub fn has_key(self: Dict<key, value>, key k: ByteArray) -> Bool {
fn do_has_key(self: Map<ByteArray, value>, key k: ByteArray) -> Bool {
when self is {
[] -> False
[Pair(k2,_), ..rest] ->
[Pair(k2, _), ..rest] ->
if builtin.less_than_equals_bytearray(k, k2) {
k == k2
} else {
Expand Down Expand Up @@ -651,15 +651,15 @@ fn do_insert(
) -> Map<ByteArray, value> {
when self is {
[] ->
[Pair(k,v)]
[Pair(k2,v2), ..rest] ->
[Pair(k, v)]
[Pair(k2, v2), ..rest] ->
if builtin.less_than_bytearray(k, k2) {
[Pair(k,v), ..self]
[Pair(k, v), ..self]
} else {
if k == k2 {
[Pair(k,v), ..rest]
[Pair(k, v), ..rest]
} else {
[Pair(k2,v2), ..do_insert(rest, k, v)]
[Pair(k2, v2), ..do_insert(rest, k, v)]
}
}
}
Expand Down Expand Up @@ -723,7 +723,7 @@ test insert_with_1() {
|> insert_with(key: "bar", value: 2, with: sum)
|> to_map()

result == [Pair("bar",2), Pair("foo",1)]
result == [Pair("bar", 2), Pair("foo", 1)]
}

test insert_with_2() {
Expand All @@ -737,7 +737,7 @@ test insert_with_2() {
|> insert_with(key: "foo", value: 3, with: sum)
|> to_map()

result == [Pair("bar",2), Pair("foo",4)]
result == [Pair("bar", 2), Pair("foo", 4)]
}

test insert_with_3() {
Expand All @@ -758,7 +758,7 @@ test insert_with_3() {
|> insert_with(key: "bar", value: 4, with: with)
|> to_map()

result == [Pair("foo",1)]
result == [Pair("foo", 1)]
}

/// Efficiently checks whether a dictionary is empty.
Expand Down Expand Up @@ -796,7 +796,7 @@ fn do_keys(self: Map<ByteArray, value>) -> List<ByteArray> {
when self is {
[] ->
[]
[Pair(k,_), ..rest] ->
[Pair(k, _), ..rest] ->
[k, ..do_keys(rest)]
}
}
Expand Down Expand Up @@ -837,8 +837,8 @@ fn do_map(
when self is {
[] ->
[]
[Pair(k,v), ..rest] ->
[Pair(k,with(k, v)), ..do_map(rest, with)]
[Pair(k, v), ..rest] ->
[Pair(k, with(k, v)), ..do_map(rest, with)]
}
}

Expand Down Expand Up @@ -877,7 +877,7 @@ test to_map_1() {
}

test to_map_2() {
to_map(fixture_1()) == [Pair(bar,14), Pair(foo,42)]
to_map(fixture_1()) == [Pair(bar, 14), Pair(foo, 42)]
}

/// Return the number of key-value pairs in the dictionary.
Expand Down Expand Up @@ -947,7 +947,7 @@ fn do_union(
) -> Map<ByteArray, value> {
when left is {
[] -> right
[Pair(k,v), ..rest] -> do_union(rest, do_insert(right, k, v))
[Pair(k, v), ..rest] -> do_union(rest, do_insert(right, k, v))
}
}

Expand All @@ -967,7 +967,9 @@ test union_3() {
new()
|> insert(bar, 42)
|> insert(baz, 1337)
union(left, right) == from_map([Pair(foo,14), Pair(baz,1337), Pair(bar,42)])
union(left, right) == from_map(
[Pair(foo, 14), Pair(baz, 1337), Pair(bar, 42)],
)
}

test union_4() {
Expand All @@ -978,7 +980,7 @@ test union_4() {
new()
|> insert(bar, 42)
|> insert(foo, 1337)
union(left, right) == from_map([Pair(foo,14), Pair(bar,42)])
union(left, right) == from_map([Pair(foo, 14), Pair(bar, 42)])
}

/// Like [`union`](#union) but allows specifying the behavior to adopt when a key is present
Expand Down Expand Up @@ -1016,7 +1018,7 @@ fn do_union_with(
) -> Map<ByteArray, value> {
when left is {
[] -> right
[Pair(k,v), ..rest] ->
[Pair(k, v), ..rest] ->
do_union_with(rest, do_insert_with(right, k, v, with), with)
}
}
Expand All @@ -1029,19 +1031,19 @@ fn do_insert_with(
) -> Map<ByteArray, value> {
when self is {
[] ->
[Pair(k,v)]
[Pair(k2,v2), ..rest] ->
[Pair(k, v)]
[Pair(k2, v2), ..rest] ->
if builtin.less_than_bytearray(k, k2) {
[Pair(k,v), ..self]
[Pair(k, v), ..self]
} else {
if k == k2 {
when with(k, v, v2) is {
Some(combined) ->
[Pair(k,combined), ..rest]
[Pair(k, combined), ..rest]
None -> rest
}
} else {
[Pair(k2,v2), ..do_insert_with(rest, k, v, with)]
[Pair(k2, v2), ..do_insert_with(rest, k, v, with)]
}
}
}
Expand All @@ -1059,7 +1061,7 @@ test union_with_1() {

let result = union_with(left, right, with: fn(_, l, r) { Some(l + r) })

result == from_map([Pair(foo,1351), Pair(bar,42)])
result == from_map([Pair(foo, 1351), Pair(bar, 42)])
}

/// Extract all the values present in a given `Dict`.
Expand All @@ -1082,7 +1084,7 @@ fn do_values(self: Map<key, value>) -> List<value> {
when self is {
[] ->
[]
[Pair(_,v), ..rest] ->
[Pair(_, v), ..rest] ->
[v, ..do_values(rest)]
}
}
Expand Down

0 comments on commit 3cfd527

Please sign in to comment.