@@ -5,17 +5,21 @@
55module Hakyll.Core.Item
66 ( Item (..)
77 , itemSetBody
8− , itemM
8+ , withItemBody
99 ) where
1010
1111
1212--------------------------------------------------------------------------------
13−import Control.Applicative ((<$>), (<*>))
14−import Data.Binary (Binary (..))
15−import Data.Typeable (Typeable)
13+import Control.Applicative (Applicative, (<$>), (<*>))
14+import Data.Binary (Binary (..))
15+import Data.Foldable (Foldable (..))
16+import Data.Traversable (Traversable (..))
17+import Data.Typeable (Typeable)
18+import Prelude hiding (foldr)
1619
1720
1821--------------------------------------------------------------------------------
22+import Hakyll.Core.Compiler.Internal
1923import Hakyll.Core.Identifier
2024
2125
@@ -31,6 +35,16 @@ instance Functor Item where
3135 fmap f (Item i x) = Item i (f x)
3236
3337
38+--------------------------------------------------------------------------------
39+instance Foldable Item where
40+ foldr f z (Item _ x) = f x z
41+
42+
43+--------------------------------------------------------------------------------
44+instance Traversable Item where
45+ traverse f (Item i x) = Item i <$> f x
46+
47+
3448--------------------------------------------------------------------------------
3549instance Binary a => Binary (Item a) where
3650 put (Item i x) = put i >> put x
@@ -43,5 +57,9 @@ itemSetBody x (Item i _) = Item i x
4357
4458
4559--------------------------------------------------------------------------------
46−itemM :: Monad m => (a -> m b) -> Item a -> m (Item b)
47−itemM f (Item i b) = f b >>= \b' -> return (Item i b')
60+-- | Perform a compiler action on the item body. This is the same as 'traverse',
61+-- but looks less intimidating.
62+--
63+-- > withItemBody = traverse
64+withItemBody :: (a -> Compiler b) -> Item a -> Compiler (Item b)
65+withItemBody = traverse