Skip to content

Instantly share code, notes, and snippets.

@fendor
Last active April 17, 2019 13:11
Show Gist options
  • Save fendor/163ba2644ea4024f1e7cd1b76be7da34 to your computer and use it in GitHub Desktop.
Save fendor/163ba2644ea4024f1e7cd1b76be7da34 to your computer and use it in GitHub Desktop.
everythingButM
:: forall r m
. (Monad m)
=> (r -> r -> r)
-> (forall a . Data a => a -> (m r, Bool))
-> (forall a . Data a => a -> m r)
everythingButM k f x = do
let (v, stop) = f x
if stop
then v
else Data.gmapQr
(\e acc -> do
e' <- e
a <- acc
return (e' `k` a)
)
v
(everythingButM k f)
x
-- -- | Variation of "everything" with an added stop condition
-- -- Just like 'everything', this is stolen from SYB package.
-- everythingBut :: (r -> r -> r)
-- -> (forall a. Data a => a -> (r, Bool))
-- -> (forall a. Data a => a -> r)
-- everythingBut k f x = let (v, stop) = f x
-- in if stop
-- then v
-- else foldl' k v (gmapQ (everythingBut k f) x)
@fendor
Copy link
Author

fendor commented Apr 17, 2019

hie-8.6.4: user error (mzero)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment