From a2f4cc41fd78cf71de233c1a7991043bc5c2d9f9 Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Tue, 27 Oct 2015 11:28:40 -0400 Subject: [PATCH] Add Functor instance for Option and OptionList --- yesod-form/Yesod/Form/Fields.hs | 11 +++++++++++ yesod-form/yesod-form.cabal | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index 5fe123ee..5ccbe208 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -591,6 +591,12 @@ data OptionList a = OptionList { olOptions :: [Option a] , olReadExternal :: Text -> Maybe a -- ^ A function mapping from the form's value ('optionExternalValue') to the selected Haskell value ('optionInternalValue'). } + +-- | Since 1.4.6 +instance Functor OptionList where + fmap f (OptionList options readExternal) = + OptionList ((fmap.fmap) f options) (fmap f . readExternal) + -- | Creates an 'OptionList', using a 'Map' to implement the 'olReadExternal' function. mkOptionList :: [Option a] -> OptionList a mkOptionList os = OptionList @@ -603,6 +609,11 @@ data Option a = Option , optionInternalValue :: a -- ^ The Haskell value being selected. , optionExternalValue :: Text -- ^ The representation of this value stored in the form. } + +-- | Since 1.4.6 +instance Functor Option where + fmap f (Option display internal external) = Option display (f internal) external + -- | Creates an 'OptionList' from a list of (display-value, internal value) pairs. optionsPairs :: (MonadHandler m, RenderMessage (HandlerSite m) msg) => [(msg, a)] -> m (OptionList a) diff --git a/yesod-form/yesod-form.cabal b/yesod-form/yesod-form.cabal index dd15539e..a7f715d5 100644 --- a/yesod-form/yesod-form.cabal +++ b/yesod-form/yesod-form.cabal @@ -1,5 +1,5 @@ name: yesod-form -version: 1.4.5 +version: 1.4.6 license: MIT license-file: LICENSE author: Michael Snoyman