def toggledPartition
[A
](xs
: List
[A
])(p
: A
=> Boolean
): List
[List
[A
]] = 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))
}
}
b2JqZWN0IE1haW4gewoKICBkZWYgdG9nZ2xlZFBhcnRpdGlvbltBXSh4czogTGlzdFtBXSkocDogQSA9PiBCb29sZWFuKTogTGlzdFtMaXN0W0FdXSA9CiAgICBpZiAoeHMuaXNFbXB0eSkgTmlsCiAgICBlbHNlIHhzIHNwYW4gcCBtYXRjaCB7IGNhc2UgKGEsYikgPT4gYSA6OiB0b2dnbGVkUGFydGl0aW9uKGIpKHggPT4gIXAoeCkpIH0KCiAgZGVmIG1haW4oYXJnczogQXJyYXlbU3RyaW5nXSkgewogICAgcHJpbnRsbih0b2dnbGVkUGFydGl0aW9uKExpc3QoMSwgMiwgMywgNCwgNSwgNiwgNSwgNCwgMywgMiwgMSwgMiwgMywgNCkpKHggPT4geCA8IDQpKQogIH0KfQ==
List(List(1, 2, 3), List(4, 5, 6, 5, 4), List(3, 2, 1, 2, 3), List(4))