Merge pull request #1095 from yesodweb/add_functor_instance_for_option
Add Functor instance for Option and OptionList
This commit is contained in:
commit
6d0affcce7
@ -591,6 +591,12 @@ data OptionList a = OptionList
|
|||||||
{ olOptions :: [Option a]
|
{ olOptions :: [Option a]
|
||||||
, olReadExternal :: Text -> Maybe a -- ^ A function mapping from the form's value ('optionExternalValue') to the selected Haskell value ('optionInternalValue').
|
, 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.
|
-- | Creates an 'OptionList', using a 'Map' to implement the 'olReadExternal' function.
|
||||||
mkOptionList :: [Option a] -> OptionList a
|
mkOptionList :: [Option a] -> OptionList a
|
||||||
mkOptionList os = OptionList
|
mkOptionList os = OptionList
|
||||||
@ -603,6 +609,11 @@ data Option a = Option
|
|||||||
, optionInternalValue :: a -- ^ The Haskell value being selected.
|
, optionInternalValue :: a -- ^ The Haskell value being selected.
|
||||||
, optionExternalValue :: Text -- ^ The representation of this value stored in the form.
|
, 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.
|
-- | Creates an 'OptionList' from a list of (display-value, internal value) pairs.
|
||||||
optionsPairs :: (MonadHandler m, RenderMessage (HandlerSite m) msg)
|
optionsPairs :: (MonadHandler m, RenderMessage (HandlerSite m) msg)
|
||||||
=> [(msg, a)] -> m (OptionList a)
|
=> [(msg, a)] -> m (OptionList a)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-form
|
name: yesod-form
|
||||||
version: 1.4.5
|
version: 1.4.6
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user