diff options
author | Erik Terpstra <erterpstra@gmail.com> | 2020-05-22 14:56:05 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-05-22 19:46:45 +0100 |
commit | c4470122c11d3b50234556f914927822455d47df (patch) | |
tree | 6a655bee54eafb5595379a4e512a830b8bedc2b3 /src | |
parent | 088ed8c9fcaaab0a434a29eb26175d4452f4b179 (diff) | |
download | gleam_stdlib-c4470122c11d3b50234556f914927822455d47df.tar.gz gleam_stdlib-c4470122c11d3b50234556f914927822455d47df.zip |
string.to_graphemes
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/string.gleam | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index cf2a585..a6c7944 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -400,14 +400,6 @@ pub fn trim_right(string: String) -> String { erl_trim(string, Trailing) } -// TODO -// /// Convert a string to a list of Graphemes. -// /// -// /// > to_graphemes("abc") -// ['a','b','c'] -// -// /// -// pub fn to_graphemes(string: String) -> List(String) {} /// Split a non-empty string into its head and tail. This lets you /// pattern match on strings exactly as you would with lists. /// @@ -420,3 +412,15 @@ pub fn trim_right(string: String) -> String { /// pub external fn pop_grapheme(string: String) -> Option(tuple(String, String)) = "gleam_stdlib" "string_pop_grapheme" + +/// Convert a string to a list of Graphemes. +/// +/// > to_graphemes("abc") +/// ["a", "b", "c"] +/// +pub fn to_graphemes(string: String) -> List(String) { + case pop_grapheme(string) { + Ok(tuple(grapheme, rest)) -> [grapheme, ..to_graphemes(rest)] + _ -> [] + } +} |