Simplify implementation of partitionM.