Something like that:
def lsplit(pos: List[Int], s: String): List[String] = pos match { case x :: rest => s.substring(0,x) :: lsplit(rest.map(_ - x), s.substring(x)) case Nil => List(s) }
(A fair warning: it is not tail recursive, so it will hit the stack for large lists, inefficient due to reassigning indices and strings of substrings. You can solve these things by adding additional arguments and / or an internal method that does recursions.)
source share