Cleanup FormResult-Instances

This commit is contained in:
Gregor Kleen 2019-03-27 00:23:30 +01:00
parent bca35ff6b6
commit 976c50f5de
4 changed files with 25 additions and 5 deletions

View File

@ -116,6 +116,7 @@ dependencies:
- lifted-base - lifted-base
- lattices - lattices
- hsass - hsass
- semigroupoids
other-extensions: other-extensions:
- GeneralizedNewtypeDeriving - GeneralizedNewtypeDeriving

View File

@ -85,11 +85,6 @@ getMsgRenderer = do
return $ MsgRenderer (mr . SomeMessage :: forall msg. RenderMessage site msg => msg -> Text) return $ MsgRenderer (mr . SomeMessage :: forall msg. RenderMessage site msg => msg -> Text)
instance Monad FormResult where
FormMissing >>= _ = FormMissing
(FormFailure errs) >>= _ = FormFailure errs
(FormSuccess a) >>= f = f a
guardAuthResult :: MonadHandler m => AuthResult -> m () guardAuthResult :: MonadHandler m => AuthResult -> m ()
guardAuthResult AuthenticationRequired = notAuthenticated guardAuthResult AuthenticationRequired = notAuthenticated
guardAuthResult (Unauthorized t) = permissionDenied t guardAuthResult (Unauthorized t) = permissionDenied t

View File

@ -3,6 +3,7 @@
module Utils.Form where module Utils.Form where
import ClassyPrelude.Yesod hiding (addMessage, cons, Proxy(..), identifyForm) import ClassyPrelude.Yesod hiding (addMessage, cons, Proxy(..), identifyForm)
import Yesod.Core.Instances ()
import Settings import Settings
import Utils.Parameters import Utils.Parameters

View File

@ -4,6 +4,7 @@ module Yesod.Core.Instances
( (
) where ) where
import Prelude (errorWithoutStackTrace)
import ClassyPrelude.Yesod import ClassyPrelude.Yesod
import Utils (assertM') import Utils (assertM')
@ -15,6 +16,9 @@ import System.FilePath ((</>))
import Data.Aeson import Data.Aeson
import Control.Monad.Fix
import Data.Functor.Extend
instance (RenderRoute site, ParseRoute site) => PathPiece (Route site) where instance (RenderRoute site, ParseRoute site) => PathPiece (Route site) where
fromPathPiece fromPathPiece
@ -39,3 +43,22 @@ instance (RenderRoute site, ParseRoute site) => FromJSON (Route site) where
instance (RenderRoute site, ParseRoute site) => ToJSON (Route site) where instance (RenderRoute site, ParseRoute site) => ToJSON (Route site) where
toJSON = String . toPathPiece toJSON = String . toPathPiece
instance Monad FormResult where
(FormSuccess a) >>= f = f a
FormMissing >>= _ = FormMissing
(FormFailure errs) >>= _ = FormFailure errs
instance MonadPlus FormResult
instance MonadFix FormResult where
mfix f = let a = f (unSuccess a) in a
where unSuccess (FormSuccess x) = x
unSuccess FormMissing = errorWithoutStackTrace "mfix FormResult: FormMissing"
unSuccess (FormFailure _) = errorWithoutStackTrace "mfix FormResult: FormFailure"
instance Extend FormResult where
duplicated (FormSuccess x) = FormSuccess $ FormSuccess x
duplicated FormMissing = FormMissing
duplicated (FormFailure errs) = FormFailure errs