aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/string.gleam9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam
index 1645894..9c1bc9e 100644
--- a/src/gleam/string.gleam
+++ b/src/gleam/string.gleam
@@ -710,9 +710,14 @@ if javascript {
/// ```
///
pub fn to_graphemes(string: String) -> List(String) {
+ do_to_graphemes(string, [])
+ |> list.reverse
+}
+
+pub fn do_to_graphemes(string: String, acc: List(String)) -> List(String) {
case pop_grapheme(string) {
- Ok(#(grapheme, rest)) -> [grapheme, ..to_graphemes(rest)]
- _ -> []
+ Ok(#(grapheme, rest)) -> do_to_graphemes(rest, [grapheme, ..acc])
+ _ -> acc
}
}