diff --git a/src/kmer.gleam b/src/kmer.gleam index 2bcfb24..0d2f8ff 100644 --- a/src/kmer.gleam +++ b/src/kmer.gleam @@ -102,7 +102,7 @@ fn decode_map( ) -> DecoderResult(List(#(DecodedValue, DecodedValue))) { use #(length, rest) <- try(decode_int(bits)) 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)) } @@ -128,18 +128,14 @@ fn decode_simple(bits: BitArray) -> DecodeResult { } } -fn into_pairs(list: List(a)) -> Result(List(#(a, a)), DecodeError) { - into_pairs_aggr([], list) -} - -fn into_pairs_aggr( +fn into_pairs( accum: List(#(a, a)), remaining: List(a), ) -> Result(List(#(a, a)), DecodeError) { case remaining { [] -> Ok(reverse(accum)) [_] -> Error(Malformed) - [key, value, ..rest] -> into_pairs_aggr([#(key, value), ..accum], rest) + [key, value, ..rest] -> into_pairs([#(key, value), ..accum], rest) } }