in reply to
Re: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
in thread Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
Generic version in the D programming language
$ cat test4.d && gdc test4.d -o test4 && echo "----" && ./test4
import std.stdio;
T[][] group(T)(T[] array) {
T[][] res;
foreach (index, elem; array) {
if (index == 0 || elem != array[index-1])
res~=(T[]).init;
res[$-1]~=elem;
}
return res;
}
void main() { writefln(group("ZBBBCZZ")); }
----
[Z,BBB,C,ZZ]