diff options
-rw-r--r-- | src/gleam/bit_builder.gleam | 20 | ||||
-rw-r--r-- | src/gleam/string_builder.gleam | 3 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/gleam/bit_builder.gleam b/src/gleam/bit_builder.gleam index b3ea755..c72b04f 100644 --- a/src/gleam/bit_builder.gleam +++ b/src/gleam/bit_builder.gleam @@ -15,6 +15,8 @@ if erlang { /// time using minimal memory, and then can be efficiently converted to a /// bit string using the `to_bit_string` function. /// + /// On Erlang this type is compatible with Erlang's iolists. + /// pub external type BitBuilder } @@ -83,7 +85,10 @@ if erlang { if javascript { fn do_append_builder(first: BitBuilder, second: BitBuilder) -> BitBuilder { - Many([first, second]) + case second { + Many(builders) -> Many([first, ..builders]) + _ -> Many([first, second]) + } } } @@ -130,7 +135,18 @@ if javascript { /// Runs in linear time otherwise. /// pub fn from_string(string: String) -> BitBuilder { - Text(string_builder.from_string(string)) + do_from_string(string) +} + +if erlang { + external fn do_from_string(String) -> BitBuilder = + "gleam_stdlib" "wrap_list" +} + +if javascript { + fn do_from_string(string: String) -> BitBuilder { + Text(string_builder.from_string(string)) + } } /// Creates a new builder from a string builder. diff --git a/src/gleam/string_builder.gleam b/src/gleam/string_builder.gleam index 0d464ca..0a90737 100644 --- a/src/gleam/string_builder.gleam +++ b/src/gleam/string_builder.gleam @@ -9,6 +9,9 @@ /// using minimal memory, and then can be efficiently converted to a string /// using the `to_string` function. /// +/// On Erlang this type is compatible with Erlang's iolists. On JavaScript this +/// type is compatible with normal strings. +/// pub external type StringBuilder /// Prepends a String onto the start of some StringBuilder. |