fork(7) download
  1. object Main {
  2.  
  3. def toggledPartition[A](xs: List[A])(p: A => Boolean): List[List[A]] =
  4. if (xs.isEmpty) Nil
  5. else xs span p match { case (a,b) => a :: toggledPartition(b)(x => !p(x)) }
  6.  
  7. def main(args: Array[String]) {
  8. println(toggledPartition(List(1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4))(x => x < 4))
  9. }
  10. }
Success #stdin #stdout 0.28s 247488KB
stdin
Standard input is empty
stdout
List(List(1, 2, 3), List(4, 5, 6, 5, 4), List(3, 2, 1, 2, 3), List(4))