Skip to content

Commit

Permalink
Add runViewForm, which always returns a view and possibly a result
Browse files Browse the repository at this point in the history
  • Loading branch information
ozataman committed Feb 12, 2012
1 parent 5dceeb3 commit 43189d0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions digestive-functors/src/Text/Digestive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Text.Digestive.Types
, (<++)
, mapView
, runForm
, runViewForm
, eitherForm
, viewForm
) where
Expand Down Expand Up @@ -206,6 +207,19 @@ eitherForm form id' env = do
Error e -> Left $ unView view' e
Ok x -> Right x

-- | Evaluate a form, return view and a result if successful
runViewForm :: Monad m
=> Form m i e v a
-> String
-> Environment m i
-> m (v, Maybe a)
runViewForm form id' env = do
(view', mresult) <- runForm form id' env
result <- mresult
return $ case result of
Error e -> (unView view' e, Nothing)
Ok x -> (unView view' [], Just x)

-- | Just evaluate the form to a view. This usually maps to a GET request in the
-- browser.
--
Expand Down

0 comments on commit 43189d0

Please sign in to comment.