{-# LANGUAGE Rank2Types #-}

module Data.Binding.Hobbits.Internal.Utilities where

import qualified Data.Generics as SYB



everywhereButM :: Monad m =>
  SYB.GenericQ Bool -> SYB.GenericM m -> SYB.GenericM m
everywhereButM :: GenericQ Bool -> GenericM m -> GenericM m
everywhereButM GenericQ Bool
q GenericM m
f a
x
  | a -> Bool
GenericQ Bool
q a
x       = a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
  | Bool
otherwise = (GenericM m -> a -> m a
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> a -> m a
SYB.gmapM (GenericQ Bool -> GenericM m -> GenericM m
forall (m :: * -> *).
Monad m =>
GenericQ Bool -> GenericM m -> GenericM m
everywhereButM GenericQ Bool
q GenericM m
f) a
x) m a -> (a -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> m a
GenericM m
f