Simply implementation of partitionM.