aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2023-10-03 20:42:28 +0100
committerLouis Pilfold <louis@lpil.uk>2023-10-03 20:42:28 +0100
commitd0d942ba9fda93a9338483335628fdae82a6fbad (patch)
treee157c69d149795ada0e2c4cf63fa06a16cf52ef2 /src
parent6ff91d92ac2a466c975c4db378740def2d2a55c6 (diff)
downloadgleam_stdlib-d0d942ba9fda93a9338483335628fdae82a6fbad.tar.gz
gleam_stdlib-d0d942ba9fda93a9338483335628fdae82a6fbad.zip
Improve pop_grapheme perf on JS
Diffstat (limited to 'src')
-rw-r--r--src/gleam/string.gleam5
1 files changed, 5 insertions, 0 deletions
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