Browse Source

rewriteBi, rewriteBiM

master
soupi 1 year ago
parent
commit
0c0dcd7ca8
2 changed files with 8 additions and 0 deletions
  1. +4
    -0
      src/Data/Generics/Plated.hs
  2. +4
    -0
      src/Data/Generics/PlatedM.hs

+ 4
- 0
src/Data/Generics/Plated.hs View File

@@ -16,6 +16,7 @@ module Data.Generics.Plated
, module Data.Generics.Plated.Universe
, para
, rewrite
, rewriteBi
)
where

@@ -31,3 +32,6 @@ rewrite :: TransformBi on on => (on -> Maybe on) -> on -> on
rewrite f = transform g
where g x = maybe x (rewrite f) (f x)

rewriteBi :: (DescendBi on from, TransformBi on on) => (on -> Maybe on) -> from -> from
rewriteBi f = descendBi (rewrite f)


+ 4
- 0
src/Data/Generics/PlatedM.hs View File

@@ -14,6 +14,7 @@ module Data.Generics.PlatedM
, module Data.Generics.Plated.DescendM
, paraM
, rewriteM
, rewriteBiM
)
where

@@ -29,3 +30,6 @@ paraM f x = f x <=< traverse (paraM f) . children $ x
rewriteM :: (Monad m, TransformBiM m on on) => (on -> m (Maybe on)) -> on -> m on
rewriteM f = transformM g
where g x = f x >>= maybe (pure x) (rewriteM f)

rewriteBiM :: (Monad m, DescendBiM m on from, TransformBiM m on on) => (on -> m (Maybe on)) -> from -> m from
rewriteBiM f = descendBiM (rewriteM f)

Loading…
Cancel
Save