De esta manera:
def splitString(xs: String, n: Int): List[String] = {
if (xs.isEmpty) Nil
else {
val (ys, zs) = xs.splitAt(n)
ys :: splitString(zs, n)
}
}
splitString("Thequickbrownfoxjumps", 4)
/************************************Executing-Process**********************************\
( ys , zs )
Theq uickbrownfoxjumps
uick brownfoxjumps
brow nfoxjumps
nfox jumps
jump s
s "" ("".isEmpty // true)
"" :: Nil ==> List("s")
"jump" :: List("s") ==> List("jump", "s")
"nfox" :: List("jump", "s") ==> List("nfox", "jump", "s")
"brow" :: List("nfox", "jump", "s") ==> List("brow", "nfox", "jump", "s")
"uick" :: List("brow", "nfox", "jump", "s") ==> List("uick", "brow", "nfox", "jump", "s")
"Theq" :: List("uick", "brow", "nfox", "jump", "s") ==> List("Theq", "uick", "brow", "nfox", "jump", "s")
\***************************************************************************/