summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2025-03-24 15:09:25 -0500
committerChris Wells <chris@mathematicaster.org>2025-03-24 15:09:27 -0500
commitd315c17b89d333d54cb2c608b7d3b3dcacb95507 (patch)
tree6e7d8ce8bd07c5c7c838c187e384578a58928caf
parentfc93851d36c45d482cc581b8a7f3611d9f6411b2 (diff)
downloadmain-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
-rw-r--r--src/Hakyll/Alias.hs6
-rw-r--r--src/Prolog.hs34
2 files changed, 35 insertions, 5 deletions
diff --git a/src/Hakyll/Alias.hs b/src/Hakyll/Alias.hs
index 4284e3d..063ea2b 100644
--- a/src/Hakyll/Alias.hs
+++ b/src/Hakyll/Alias.hs
@@ -22,10 +22,10 @@ aliasCtxt name toa fromx amap = functionField1 name $ toa >=> flip resolveAlias
personCtxt :: (StringConv StrictText s, Ord (Name s), ToMarkup s) => AliasMap (Name s) (Person s) -> Context a
-personCtxt = aliasCtxt "person" (fmap (fmap toSL) . parseName . toSL) (pure . toSL . personHtml)
+personCtxt = aliasCtxt "personA" (ffmap toSL . parseName . toSL) (pure . toSL . personHtml)
licenseCtxt :: (StringConv String s, Ord s, ToMarkup s) => AliasMap s (License s) -> Context a
-licenseCtxt = aliasCtxt "license" (pure . toSL) (pure . toSL . licenseHtml)
+licenseCtxt = aliasCtxt "licenseA" (pure . toSL) (pure . toSL . licenseHtml)
journalCtxt :: (StringConv String s, Ord s, ToMarkup s) => AliasMap s (Journal s) -> Context a
-journalCtxt = aliasCtxt "journal" (pure . toSL) (pure . toSL . journalHtml)
+journalCtxt = aliasCtxt "journalA" (pure . toSL) (pure . toSL . journalHtml)
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