on master help sign in
Arrow version of addField
1f169ddJasper Van der Jeugt
src/Text/Hakyll/CreateContext.hs+8−4
@@ -10,11 +10,14 @@ module Text.Hakyll.CreateContext
10 , combineWithUrl
10 , combineWithUrl
11 ) where
11 ) where
12
12
13+import Prelude hiding (id)
14+
13import qualified Data.Map as M
15import qualified Data.Map as M
14−import Control.Arrow (second, arr, (&&&))
16+import Control.Arrow (second, arr, (&&&), (***))
15import Control.Monad (liftM2)
17import Control.Monad (liftM2)
16import Control.Applicative ((<$>))
18import Control.Applicative ((<$>))
17import Control.Arrow ((>>>))
19import Control.Arrow ((>>>))
20+import Control.Category (id)
18
21
19import Text.Hakyll.Context
22import Text.Hakyll.Context
20import Text.Hakyll.HakyllAction
23import Text.Hakyll.HakyllAction
@@ -73,9 +76,10 @@ createListing url templates renderables additional =
73--
76--
74addField :: String -- ^ Key
77addField :: String -- ^ Key
75 -> Either String (HakyllAction () String) -- ^ Value
78 -> Either String (HakyllAction () String) -- ^ Value
76− -> HakyllAction a Context -- ^ Target
79+ -> HakyllAction Context Context -- ^ Result
77− -> HakyllAction a Context -- ^ Result
80+addField key value = arr (const ()) &&& id
81+ >>> value' *** id
78−addField key value target = value' &&& target >>> arr (uncurry insert)
82+ >>> arr (uncurry insert)
79 where
83 where
80 value' = arr (const ()) >>> either (arr . const) id value
84 value' = arr (const ()) >>> either (arr . const) id value
81 insert v = Context . M.insert key v . unContext
85 insert v = Context . M.insert key v . unContext