lucienne-0.0.1: Lucienne/Fetch/Util.hs
module Lucienne.Fetch.Util
(partitionM)
where
import Control.Monad (foldM)
-- Note: order of elements is reversed in result
partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a],[a])
partitionM p = foldM (selectM p) ([],[])
selectM :: Monad m => (a -> m Bool) -> ([a], [a]) -> a -> m ([a], [a])
selectM p (ts,fs) x = do
true <- p x
return $ if true then (x:ts, fs) else (ts, x:fs)