diff options
| author | Chris Wells <chris@mathematicaster.org> | 2025-03-24 15:09:25 -0500 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2025-03-24 15:09:27 -0500 |
| commit | d315c17b89d333d54cb2c608b7d3b3dcacb95507 (patch) | |
| tree | 6e7d8ce8bd07c5c7c838c187e384578a58928caf /src/Prolog.hs | |
| parent | fc93851d36c45d482cc581b8a7f3611d9f6411b2 (diff) | |
| download | main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.tar main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.tar.gz main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.tar.bz2 main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.tar.lz main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.tar.xz main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.tar.zst main-d315c17b89d333d54cb2c608b7d3b3dcacb95507.zip | |
Extra utils
Diffstat (limited to 'src/Prolog.hs')
| -rw-r--r-- | src/Prolog.hs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/Prolog.hs b/src/Prolog.hs index 145f2d3..94a6eb6 100644 --- a/src/Prolog.hs +++ b/src/Prolog.hs @@ -43,7 +43,9 @@ module Prolog , renderTo , fromStringlike -- * Utils + , ffmap , (<<$>>) + , fffmap , (<<<$>>>) , (<<&>>) , (-->) @@ -54,6 +56,9 @@ module Prolog , squashMaybe , throwEither , squashEither + , rebase + , rebaseWith + , rebaseWithM ) where import Control.Applicative @@ -100,14 +105,26 @@ import Text.LaTeX.Packages.Hyperref qualified as LH type StrictText = T.Text type LazyText = TL.Text +-- | 'fmap' over nested functors +ffmap :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) +ffmap = fmap fmap fmap +{-# INLINE ffmap #-} + +-- | Infix version of 'ffmap' (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) infixl 4 <<$>> -(<<$>>) = fmap fmap fmap +(<<$>>) = ffmap {-# INLINE (<<$>>) #-} +-- | 'fmap' over nested functors +fffmap :: (Functor f, Functor g, Functor h) => (a -> b) -> f (g (h a)) -> f (g (h b)) +fffmap = fmap . fmap . fmap +{-# INLINE fffmap #-} + +-- | Infix version of 'fffmap' (<<<$>>>) :: (Functor f, Functor g, Functor h) => (a -> b) -> f (g (h a)) -> f (g (h b)) infixl 4 <<<$>>> -(<<<$>>>) = fmap . fmap . fmap +(<<<$>>>) = fffmap {-# INLINE (<<<$>>>) #-} (<<&>>) :: (Functor f, Functor g) => f (g a) -> (a -> b) -> f (g b) @@ -160,6 +177,19 @@ fromStringlike :: (IsString s, StringConv t String) => t -> s fromStringlike = fromString . toSL {-# INLINE fromStringlike #-} + +rebase :: (Applicative m, Comonad w) => w a -> m a +rebase = rebaseWith id +{-# INLINE rebase #-} + +rebaseWith :: (Applicative m, Comonad w) => (a -> b) -> w a -> m b +rebaseWith f = rebaseWithM $ pure . f +{-# INLINE rebaseWith #-} + +rebaseWithM :: (Applicative m, Comonad w) => (a -> m b) -> w a -> m b +rebaseWithM f = f . extract +{-# INLINE rebaseWithM #-} + -- Orphan instances |
