Skip to content

Instantly share code, notes, and snippets.

@almendar
Created September 11, 2013 18:13
Show Gist options
  • Save almendar/6527517 to your computer and use it in GitHub Desktop.
Save almendar/6527517 to your computer and use it in GitHub Desktop.
def p9[T](list: Seq[T]): Seq[Seq[T]] = {
@tailrec
def p9acc[T](list: Seq[T],acc:Seq[Seq[T]]): Seq[Seq[T]] = {
list match {
case Nil => acc
case x::xs =>
val (pref, suf) = list.span(_ == list.head)
p9acc(suf,pref+:acc)
}
}
p9acc(list,Nil).reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment