yesod-form 1.3.15.4 → 1.3.16
raw patch · 2 files changed
+28/−1 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Yesod.Form.Functions: convertField :: Functor m => (a -> b) -> (b -> a) -> Field m a -> Field m b
Files
- Yesod/Form/Functions.hs +27/−0
- yesod-form.cabal +1/−1
Yesod/Form/Functions.hs view
@@ -45,6 +45,7 @@ , fieldSettingsLabel , parseHelper , parseHelperGen+ , convertField ) where import Yesod.Form.Types@@ -526,3 +527,29 @@ parseHelperGen _ [] _ = return $ Right Nothing parseHelperGen _ ("":_) _ = return $ Right Nothing parseHelperGen f (x:_) _ = return $ either (Left . SomeMessage) (Right . Just) $ f x++-- | Since a 'Field' cannot be a 'Functor', it is not obvious how to "reuse" a Field+-- on a @newtype@ or otherwise equivalent type. This function allows you to convert+-- a @Field m a@ to a @Field m b@ assuming you provide a bidireccional+-- convertion among the two, through the first two functions.+--+-- A simple example:+--+-- > import Data.Monoid+-- > sumField :: (Functor m, Monad m, RenderMessage (HandlerSite m) FormMessage) => Field m (Sum Int)+-- > sumField = convertField Sum getSum intField+--+-- Another example, not using a newtype, but instead creating a Lazy Text field:+--+-- > import qualified Data.Text.Lazy as TL+-- > TextField :: (Functor m, Monad m, RenderMessage (HandlerSite m) FormMessage) => Field m TL.Text+-- > lazyTextField = convertField TL.fromStrict TL.toStrict textField+--+-- Since 1.3.16+convertField :: (Functor m)+ => (a -> b) -> (b -> a)+ -> Field m a -> Field m b+convertField to from (Field fParse fView fEnctype) = let+ fParse' ts = fmap (fmap (fmap to)) . fParse ts+ fView' ti tn at ei = fView ti tn at (fmap from ei)+ in Field fParse' fView' fEnctype
yesod-form.cabal view
@@ -1,5 +1,5 @@ name: yesod-form-version: 1.3.15.4+version: 1.3.16 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>