module Imp.Extra.HsModule where

import qualified GHC.Hs as Hs
import qualified Imp.Ghc as Ghc

overDecls ::
  (Functor f) =>
  ([Hs.LHsDecl Hs.GhcPs] -> f [Hs.LHsDecl Hs.GhcPs]) ->
  Ghc.HsModulePs ->
  f Ghc.HsModulePs
overDecls :: forall (f :: * -> *).
Functor f =>
([LHsDecl GhcPs] -> f [LHsDecl GhcPs])
-> HsModulePs -> f HsModulePs
overDecls [LHsDecl GhcPs] -> f [LHsDecl GhcPs]
f HsModulePs
x = (\[GenLocated SrcSpanAnnA (HsDecl GhcPs)]
y -> HsModulePs
x {Hs.hsmodDecls = y}) ([GenLocated SrcSpanAnnA (HsDecl GhcPs)] -> HsModulePs)
-> f [GenLocated SrcSpanAnnA (HsDecl GhcPs)] -> f HsModulePs
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsDecl GhcPs] -> f [LHsDecl GhcPs]
f (HsModulePs -> [LHsDecl GhcPs]
forall p. HsModule p -> [LHsDecl p]
Hs.hsmodDecls HsModulePs
x)

overImports ::
  ([Hs.LImportDecl Hs.GhcPs] -> [Hs.LImportDecl Hs.GhcPs]) ->
  Ghc.HsModulePs ->
  Ghc.HsModulePs
overImports :: ([LImportDecl GhcPs] -> [LImportDecl GhcPs])
-> HsModulePs -> HsModulePs
overImports [LImportDecl GhcPs] -> [LImportDecl GhcPs]
f HsModulePs
x = HsModulePs
x {Hs.hsmodImports = f $ Hs.hsmodImports x}