Skip to content

Commit

Permalink
Add spanM
Browse files Browse the repository at this point in the history
  • Loading branch information
puffnfresh committed Jul 7, 2016
1 parent f2fd736 commit 9b9bfa5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Control/Monad/Loops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ dropWhileM p (x:xs) = do
then dropWhileM p xs
else return (x:xs)

-- | Monad 'span'.
spanM :: (Monad m) => (a -> m Bool) -> [a] -> m ([a], [a])
spanM _ [] = return []
spanM p xs@(x:xs') = do
q <- p x
if q
then do
(ys, zs) <- spanM p xs'
return (x:ys, zs)
else return ([], xs)

-- |like 'dropWhileM' but trims both ends of the list.
trimM :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
trimM p xs = do
Expand Down

0 comments on commit 9b9bfa5

Please sign in to comment.