language: Scala (scala-2.10.0)
date: 366 days 12 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
object Main {
 
  def toggledPartition[A](xs: List[A])(p: A => Boolean): List[List[A]] =
    if (xs.isEmpty) Nil
    else xs span p match { case (a,b) => a :: toggledPartition(b)(x => !p(x)) }
 
  def main(args: Array[String]) {
    println(toggledPartition(List(1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4))(x => x < 4))
  }
}