Search code examples
stringdartiterationiterable

Dart String Iterable interface


Why doesn't Dart String class implement the iterable interface? It seems like there is an obvious notion of iteration for strings, i.e. just return each character in turn.


Solution

  • Maybe not that terse as you would like

    String s = 'foo';
    s.codeUnits.forEach((f) => print(new String.fromCharCode(f)));
    s.runes.forEach((f) => print(new String.fromCharCode(f)));