Add partition-then-fold as suggested by @stuarthalloway