diff options
author | sobolevn <mail@sobolevn.me> | 2024-08-20 10:31:20 +0300 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-08-24 13:07:53 +0100 |
commit | e57ea3d5b73f9143071941ec0da0b6c38de7d86a (patch) | |
tree | 913246f398b404d8f48efddef866454d19aad20f /src | |
parent | 7f348a800e676f753756712673aabc5dde66594d (diff) | |
download | gleam_stdlib-e57ea3d5b73f9143071941ec0da0b6c38de7d86a.tar.gz gleam_stdlib-e57ea3d5b73f9143071941ec0da0b6c38de7d86a.zip |
Address review
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/bit_array.gleam | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/gleam/bit_array.gleam b/src/gleam/bit_array.gleam index 8c3ce48..cba8da9 100644 --- a/src/gleam/bit_array.gleam +++ b/src/gleam/bit_array.gleam @@ -200,26 +200,24 @@ fn do_inspect(input: BitArray, accumulator: String) -> String { /// compare(<<"AB":utf8>>, <<"AA":utf8>>) /// // -> Gt /// -/// compare(<<1, 2:size(2)>>, <<1, 2:size(2)>>) +/// compare(<<1, 2:size(2)>>, with: <<1, 2:size(2)>>) /// // -> Eq /// ``` /// /// Only supported on Erlang target for now. /// -pub fn compare(first: BitArray, second: BitArray) -> order.Order { - do_compare(first, second) +pub fn compare(a: BitArray, with b: BitArray) -> order.Order { + do_compare(a, b) } -@target(javascript) @external(javascript, "../gleam_stdlib.mjs", "bit_array_compare") -fn do_compare(first: BitArray, second: BitArray) -> order.Order - -@target(erlang) -fn do_compare(first: BitArray, second: BitArray) -> order.Order { - case first, second { +fn do_compare(a: BitArray, with b: BitArray) -> order.Order { + case a, b { <<first_byte, first_rest:bits>>, <<second_byte, second_rest:bits>> -> - int.compare(first_byte, second_byte) - |> order.lazy_break_tie(fn() { compare(first_rest, second_rest) }) + case int.compare(first_byte, second_byte) { + order.Eq -> compare(first_rest, second_rest) + result -> result + } <<>>, <<>> -> order.Eq // First has more items, example: "AB" > "A": @@ -233,6 +231,5 @@ fn do_compare(first: BitArray, second: BitArray) -> order.Order { } } -@target(erlang) @external(erlang, "gleam_stdlib", "bit_array_to_int") -fn bit_array_to_int(first: BitArray) -> Int +fn bit_array_to_int(a: BitArray) -> Int |