From 8f6384317ea5d62b5234a876d6f00abe31e8c24b Mon Sep 17 00:00:00 2001 From: joe Date: Sat, 29 Jun 2013 16:43:16 -0400 Subject: NestingXML utilities --- Presence/NestingXML.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Presence') diff --git a/Presence/NestingXML.hs b/Presence/NestingXML.hs index 220e82a0..cf4fcd93 100644 --- a/Presence/NestingXML.hs +++ b/Presence/NestingXML.hs @@ -9,6 +9,9 @@ type NestingXML o m a = ReaderT Int (ConduitM Event o m) a runNestingXML :: NestingXML o m a -> Int -> ConduitM Event o m a runNestingXML = runReaderT +doNestingXML :: NestingXML o m a -> ConduitM Event o m a +doNestingXML = flip runNestingXML 0 + nesting :: Monad m => NestingXML o m Int nesting = ask @@ -21,6 +24,17 @@ awaitXML = do _ -> id local f (return xml) +withXML + :: Monad m => (Event -> NestingXML o m ()) -> NestingXML o m () +withXML f = do + xml <- awaitXML + maybe (return ()) f xml + +maybeXML + :: Monad m => NestingXML o m a -> (Event -> NestingXML o m a) -> NestingXML o m a +maybeXML whenNothing withJust = do + xml <- awaitXML + maybe whenNothing withJust xml awaitCloser :: Monad m => Int -> NestingXML o m () awaitCloser lvl = do -- cgit v1.2.3