summaryrefslogtreecommitdiff
path: root/src/Prolog.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Prolog.hs')
-rw-r--r--src/Prolog.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Prolog.hs b/src/Prolog.hs
index 70545c9..a688063 100644
--- a/src/Prolog.hs
+++ b/src/Prolog.hs
@@ -36,18 +36,22 @@ module Prolog
, toSL
, convS
, convSL
+ , renderTo
+ , fromStringlike
-- * Utils
, (<<$>>)
, (<<<$>>>)
, (<<&>>)
, (-->)
, (-/>)
+ , (>>=?)
, foreach
, liftMaybe
, squashMaybe
) where
import Control.Applicative
+import Control.Comonad
import Control.Monad
import Control.Monad.Catch
import Control.Monad.Except
@@ -110,6 +114,12 @@ infixr 0 -/>
(-/>) = (-->) . fmap not
{-# INLINE (-/>) #-}
+(>>=?) :: (Monad m, Monoid w) => m (Maybe a) -> (a -> m w) -> m w
+infixl 1 >>=?
+x >>=? f = x >>= maybe (pure mempty) f
+{-# INLINE (>>=?) #-}
+
+
liftMaybe :: Alternative m => Maybe a -> m a
liftMaybe = maybe empty pure
{-# INLINE liftMaybe #-}
@@ -118,6 +128,13 @@ squashMaybe :: Alternative m => m (Maybe a) -> m a
squashmaybe = (>>= liftMaybe)
{-# INLINE squashMaybe #-}
+renderTo :: (StringConv T.Text s, L.Render r) => r -> s
+renderTo = toSL . L.render
+{-# INLINE renderTo #-}
+
+fromStringlike :: (IsString s, StringConv t String) => t -> s
+fromStringlike = fromString . toSL
+{-# INLINE fromStringlike #-}
-- Orphan instances
@@ -134,6 +151,9 @@ instance H.Writable L.LaTeX where
instance Contravariant H.Context where
contramap f (H.Context c) = H.Context $ \x xs -> c x xs . fmap f
+instance Comonad H.Item where
+ extract = H.itemBody
+ duplicate = join (<$)
instance StringConv L.LaTeX T.Text where
strConv _ = L.render