diff options
author | inoas <mail@inoas.com> | 2022-09-19 12:14:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-19 13:14:53 +0100 |
commit | de55a928a712df78faad08a9e9aafea7717d3190 (patch) | |
tree | 9a6539c99fb9502956ea2ac72c5d677f04fcf75b /src | |
parent | 0076b6f2bef09c2b1cf7f14c3da12faa8b2a4c11 (diff) | |
download | gleam_stdlib-de55a928a712df78faad08a9e9aafea7717d3190.tar.gz gleam_stdlib-de55a928a712df78faad08a9e9aafea7717d3190.zip |
String slice tco (#338)
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/string.gleam | 9 |
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 } } |