aboutsummaryrefslogtreecommitdiff
path: root/src/iodata.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'src/iodata.gleam')
-rw-r--r--src/iodata.gleam41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/iodata.gleam b/src/iodata.gleam
index 856832f..81329d0 100644
--- a/src/iodata.gleam
+++ b/src/iodata.gleam
@@ -11,7 +11,16 @@ pub external fn prepend(Iodata, String) -> Iodata =
pub external fn append(Iodata, String) -> Iodata =
"gleam__stdlib" "iodata_append";
-pub external fn concat(List(String)) -> Iodata =
+pub external fn prepend_iodata(Iodata, Iodata) -> Iodata =
+ "gleam__stdlib" "iodata_prepend";
+
+pub external fn append_iodata(Iodata, Iodata) -> Iodata =
+ "gleam__stdlib" "iodata_append";
+
+pub external fn from_strings(List(String)) -> Iodata =
+ "gleam__stdlib" "identity";
+
+pub external fn concat(List(Iodata)) -> Iodata =
"gleam__stdlib" "identity";
pub external fn new(String) -> Iodata =
@@ -23,6 +32,9 @@ pub external fn to_string(Iodata) -> String =
pub external fn byte_size(Iodata) -> Int =
"erlang" "iolist_size";
+pub external fn from_float(Float) -> Iodata =
+ "io_lib_format" "fwrite_g";
+
test iodata {
let iodata = new("ello")
|> append(_, ",")
@@ -36,13 +48,26 @@ test iodata {
iodata
|> byte_size
|> expect:equal(_, 13)
+
+ let iodata = new("ello")
+ |> append_iodata(_, new(","))
+ |> append_iodata(_, concat([new(" wo"), new("rld!")]))
+ |> prepend_iodata(_, new("H"))
+
+ iodata
+ |> to_string
+ |> expect:equal(_, "Hello, world!")
+
+ iodata
+ |> byte_size
+ |> expect:equal(_, 13)
}
pub external fn lowercase(Iodata) -> Iodata = "string" "lowercase"
test lowercase {
["Gleam", "Gleam"]
- |> concat
+ |> from_strings
|> lowercase
|> to_string
|> expect:equal(_, "gleamgleam")
@@ -52,7 +77,7 @@ pub external fn uppercase(Iodata) -> Iodata = "string" "uppercase"
test uppercase {
["Gleam", "Gleam"]
- |> concat
+ |> from_strings
|> uppercase
|> to_string
|> expect:equal(_, "GLEAMGLEAM")
@@ -77,9 +102,9 @@ test split {
|> expect:equal(_, [new("Gleam"), new("Erlang"), new("Elixir")])
["Gleam, Erl", "ang,Elixir"]
- |> concat
+ |> from_strings
|> split(_, ", ")
- |> expect:equal(_, [new("Gleam"), concat(["Erl", "ang,Elixir"])])
+ |> expect:equal(_, [new("Gleam"), from_strings(["Erl", "ang,Elixir"])])
}
external fn erl_replace(Iodata, String, String, Direction) -> Iodata =
@@ -93,7 +118,7 @@ pub external fn is_equal(Iodata, Iodata) -> Bool = "string" "equal"
test is_equal {
new("12")
- |> is_equal(_, concat(["1", "2"]))
+ |> is_equal(_, from_strings(["1", "2"]))
|> expect:true
new("12")
@@ -116,11 +141,11 @@ test is_empty {
|> is_empty
|> expect:false
- concat([])
+ from_strings([])
|> is_empty
|> expect:true
- concat(["", ""])
+ from_strings(["", ""])
|> is_empty
|> expect:true
}