minor private fn cleanup
All checks were successful
test / test (push) Successful in 1m39s

This commit is contained in:
Hamcha 2024-11-30 21:24:07 +01:00
parent d8ffd4a9bd
commit a61dc3d878
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89

View file

@ -102,7 +102,7 @@ fn decode_map(
) -> DecoderResult(List(#(DecodedValue, DecodedValue))) { ) -> DecoderResult(List(#(DecodedValue, DecodedValue))) {
use #(length, rest) <- try(decode_int(bits)) use #(length, rest) <- try(decode_int(bits))
use #(entries, remainder) <- try(decode_next_n([], rest, length * 2)) use #(entries, remainder) <- try(decode_next_n([], rest, length * 2))
use pairs <- try(into_pairs(entries)) use pairs <- try(into_pairs([], entries))
Ok(#(pairs, remainder)) Ok(#(pairs, remainder))
} }
@ -128,18 +128,14 @@ fn decode_simple(bits: BitArray) -> DecodeResult {
} }
} }
fn into_pairs(list: List(a)) -> Result(List(#(a, a)), DecodeError) { fn into_pairs(
into_pairs_aggr([], list)
}
fn into_pairs_aggr(
accum: List(#(a, a)), accum: List(#(a, a)),
remaining: List(a), remaining: List(a),
) -> Result(List(#(a, a)), DecodeError) { ) -> Result(List(#(a, a)), DecodeError) {
case remaining { case remaining {
[] -> Ok(reverse(accum)) [] -> Ok(reverse(accum))
[_] -> Error(Malformed) [_] -> Error(Malformed)
[key, value, ..rest] -> into_pairs_aggr([#(key, value), ..accum], rest) [key, value, ..rest] -> into_pairs([#(key, value), ..accum], rest)
} }
} }