Skip to content

Commit 4f251a0

Browse files
committed
rewrite from_asset_list to avoid expect with only discards.
1 parent 6952d47 commit 4f251a0

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

lib/cardano/assets.ak

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,19 @@ pub fn from_asset_list(xs: Pairs<PolicyId, Pairs<AssetName, Int>>) -> Value {
8888
xs
8989
|> list.foldr(
9090
dict.empty,
91-
fn(inner, acc) {
92-
expect Pair(p, [_, ..] as x) = inner
93-
x
94-
|> dict.from_ascending_pairs_with(fn(v) { 0 != v })
95-
|> dict.insert_with(acc, p, _, dict_strategy.expect_no_duplicate())
91+
fn(Pair(policy, assets), acc) {
92+
when assets is {
93+
[] -> fail @"from_asset_list: empty assets"
94+
_ ->
95+
assets
96+
|> dict.from_ascending_pairs_with(fn(v) { 0 != v })
97+
|> dict.insert_with(
98+
acc,
99+
policy,
100+
_,
101+
dict_strategy.expect_no_duplicate(),
102+
)
103+
}
96104
},
97105
)
98106
|> Value

0 commit comments

Comments
 (0)