Commits

Luke Plant committed 14c53ed

Pulled out 'apply' and 'with' functions

  • Participants
  • Parent commits b7c1842

Comments (0)

Files changed (2)

File src/Web/GenUtils.hs

+-- | General utility functions that do not depend on other functions
+-- in Web modules
+module Web.GenUtils
+
+where
+
+
+-- | Apply a list of transformation functions to an object
+apply :: [a -> a] -- ^ List of functions
+      -> a        -- ^ Initial value
+      -> a
+apply fs init = foldl (flip ($)) init fs
+
+-- | Same as apply with arguments flipped
+with = flip apply

File src/Web/Response.hs

 import Data.List
 import Network.CGI.Protocol (Headers, HeaderName(HeaderName))
 import Network.CGI (ContentType(ContentType), showContentType)
+import Web.GenUtils (apply)
 
 data Response = Response {
       content :: ByteString
 -- | Build a Response from a list of Response transformation functions
 -- and an initial Response
 buildResponse :: [Response -> Response] -> Response -> Response
-buildResponse fs rinit = foldl (flip ($)) rinit fs
+buildResponse = apply
 
 allHeaders resp =
     let statusHeader = (HeaderName "Status", show $ status resp)