diff options
| author | Chris Wells <chris@mathematicaster.org> | 2025-01-11 10:28:34 -0600 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2025-01-11 10:28:34 -0600 |
| commit | 1a3ecbb58d85f70be0625777f9deb9a58907d2e2 (patch) | |
| tree | 88ab89ecbe8946b06e09ab0e594878f8572e72de /src/Prolog.hs | |
| parent | 42a2d42eecf551dd1990c97c1ae2586cd46674be (diff) | |
| download | main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.tar main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.tar.gz main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.tar.bz2 main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.tar.lz main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.tar.xz main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.tar.zst main-1a3ecbb58d85f70be0625777f9deb9a58907d2e2.zip | |
More basic modules for errors and parsers
Diffstat (limited to 'src/Prolog.hs')
| -rw-r--r-- | src/Prolog.hs | 20 |
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 |
