aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2021-08-08 21:35:43 +0100
committerLouis Pilfold <louis@lpil.uk>2021-08-08 21:35:43 +0100
commitf62897a4877524a9515e6f703794d50db89c3f99 (patch)
tree43bf29210dfd7cf59435b0dc4214c43709b27a3d
parent6176988e37845fd6dde805dc022e85370cbe7d6e (diff)
downloadgleam_stdlib-f62897a4877524a9515e6f703794d50db89c3f99.tar.gz
gleam_stdlib-f62897a4877524a9515e6f703794d50db89c3f99.zip
Fix Erlang comp
-rw-r--r--src/gleam/bit_builder.gleam20
-rw-r--r--src/gleam/string_builder.gleam3
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.