groupByString function
Group characters together if they meet criteria.
Implementation
List<String> groupByString(
bool Function(String a, String b) groupFunction, String s) {
if (s.isEmpty) {
return [];
}
List<String> groups = [];
String currentGroup = s.substring(0, 1);
for (int i = 1; i < s.length; i++) {
if (groupFunction(s.substring(i - 1, i), s.substring(i, i + 1))) {
currentGroup += (s.substring(i, i + 1));
if (i == s.length - 1) {
groups.add(currentGroup);
}
} else {
groups.add(currentGroup);
currentGroup = s.substring(i, i + 1);
if (i == s.length - 1) {
groups.add(currentGroup);
}
continue;
}
}
return groups;
}