4 ms·
Ruby gives you the choice to iterate over all types, via `each_byte`, `each_char`, `each_codepoint`, or `each_grapheme_cluster`. https://ruby-doc.org/3.2.2/Str
by omoikane 3y ago
Ruby gives you the choice to iterate over all types, via `each_byte`, `each_char`, `each_codepoint`, or `each_grapheme_cluster`.
https://ruby-doc.org/3.2.2/String.html#class-String-label-Methods+for+Iterating https://ruby-doc.org/3.2.2/String.html#class-String-label-Me...
- h0l0cube 3y agoElixir also makes this distinction: https://hexdocs.pm/elixir/1.12/String.html#module-code-points-and-grapheme-cluster https://hexdocs.pm/elixir/1.12/String.html#module-code-point...
- nerdponx 3y agoPython would benefit from this significantly IMO.
- sundarurfriend 3y agoIn Julia, iterating over a string by default behaves like `each_char`. `codeunits(str)` lets you access the underlying code units, which is bytes for the default UTF-8 encoding. (External packages implement UTF-16 and others, and there `codeunits` could return non-bytes, for eg. 16-bit values for UTF-16.) The Unicode stdlib provides `graphemes(str)`, the equivalent of `each_grapheme_cluster`.