diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/gleam/string.gleam | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2422e7e..d553c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Improved performance of `string.to_graphemes` on JavaScript. - The `iterator` module gains the `map2` function. - The `list` module gains the `key_filter` function. diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 39a69d3..5a85cc3 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -679,6 +679,10 @@ fn do_trim_right(string string: String) -> String /// Splits a non-empty `String` into its first element (head) and rest (tail). /// This lets you pattern match on `String`s exactly as you would with lists. /// +/// Note on JavaScript using the function to iterate over a string will likely +/// be slower than using `to_graphemes` due to string slicing being more +/// expensive on JavaScript than Erlang. +/// /// ## Examples /// /// ```gleam @@ -707,6 +711,7 @@ fn do_pop_grapheme(string string: String) -> Result(#(String, String), Nil) /// ["a", "b", "c"] /// ``` /// +@external(javascript, "../gleam_stdlib.mjs", "graphemes") pub fn to_graphemes(string: String) -> List(String) { do_to_graphemes(string, []) |> list.reverse |