I\'m trying to \'group\' a string into segments, I guess this example would explain it more succintly
scala> val str: String = \"aaaabbcddeeeeeeffg\"
...
You could use some helper functions like this:
val str = "aaaabbcffffddeeeeefff"
def zame(chars:List[Char]) = chars.partition(_==chars.head)
def q(chars:List[Char]):List[List[Char]] = chars match {
case Nil => Nil
case rest =>
val (thesame,others) = zame(rest)
thesame :: q(others)
}
q(str.toList) map (_.mkString)
This should do the trick, right? No doubt it can be cleaned up into one-liners even further