Last active
April 17, 2019 13:11
-
-
Save fendor/163ba2644ea4024f1e7cd1b76be7da34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hie-8.6.4: user error (mzero)