Add foldr-based partition function