Proposal: add 'partitionM' to Control.Monad module

Heka Treep zena.treep at gmail.com
Wed Jun 8 13:54:28 CEST 2011


filterM is already exist, partitionM is quite similar:

-- | This generalizes the list-based 'partition' function.
partitionM :: (Monad m) => (a -> m Bool) -> [a] -> m ([a], [a])
partitionM _ []     = return ([], [])
partitionM p (x:xs) = do
  test      <- p x
  (ys, ys') <- partitionM p xs
  return $ if test then (x:ys, ys') else (ys, x:ys')



More information about the Libraries mailing list