Give FormResult an Alternative instance
This commit is contained in:
parent
4f14b9b82d
commit
f08944d888
@ -1,3 +1,7 @@
|
||||
## 1.4.15
|
||||
|
||||
* Added `Alternative` instance to `FormResult` to simplify handling pages with multiple forms.
|
||||
|
||||
## 1.4.14
|
||||
|
||||
* Added `WForm` to reduce the verbosity using monadic forms.
|
||||
|
||||
@ -30,7 +30,7 @@ import Text.Blaze (Markup, ToMarkup (toMarkup), ToValue (toValue))
|
||||
#define Html Markup
|
||||
#define ToHtml ToMarkup
|
||||
#define toHtml toMarkup
|
||||
import Control.Applicative ((<$>), Applicative (..))
|
||||
import Control.Applicative ((<$>), Alternative (..), Applicative (..))
|
||||
import Control.Monad (liftM)
|
||||
import Control.Monad.Trans.Class
|
||||
import Data.String (IsString (..))
|
||||
@ -45,6 +45,8 @@ import Data.Foldable
|
||||
--
|
||||
-- The 'Applicative' instance will concatenate the failure messages in two
|
||||
-- 'FormResult's.
|
||||
-- The 'Alternative' instance will choose 'FormFailure' before 'FormSuccess',
|
||||
-- and 'FormMissing' last of all.
|
||||
data FormResult a = FormMissing
|
||||
| FormFailure [Text]
|
||||
| FormSuccess a
|
||||
@ -80,6 +82,16 @@ instance Data.Traversable.Traversable FormResult where
|
||||
FormFailure errs -> pure (FormFailure errs)
|
||||
FormMissing -> pure FormMissing
|
||||
|
||||
-- | @since 1.4.15
|
||||
instance Alternative FormResult where
|
||||
empty = FormMissing
|
||||
|
||||
FormFailure e <|> _ = FormFailure e
|
||||
_ <|> FormFailure e = FormFailure e
|
||||
FormSuccess s <|> FormSuccess _ = FormSuccess s
|
||||
FormMissing <|> result = result
|
||||
result <|> FormMissing = result
|
||||
|
||||
-- | The encoding type required by a form. The 'ToHtml' instance produces values
|
||||
-- that can be inserted directly into HTML.
|
||||
data Enctype = UrlEncoded | Multipart
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod-form
|
||||
version: 1.4.14
|
||||
version: 1.4.15
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user