Skip to content

Commit

Permalink
添加mapActionT,自由变换monad。
Browse files Browse the repository at this point in the history
  • Loading branch information
kalxd committed Sep 4, 2021
1 parent 3c1be3f commit 888fa1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Yue/Internal/Type/Action.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Yue.Internal.Type.Action where

import Prelude

import Control.Monad.Except.Trans (ExceptT, catchError, throwError)
import Control.Monad.Reader.Trans (ReaderT)
import Control.Monad.State.Trans (StateT)
import Control.Monad.Except.Trans (ExceptT, catchError, mapExceptT, throwError)
import Control.Monad.Reader.Trans (ReaderT, mapReaderT)
import Control.Monad.State.Trans (StateT, mapStateT)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..), fromMaybe)
import Node.HTTP (Request, Response, requestURL)
Expand Down Expand Up @@ -49,3 +49,8 @@ catchAction action = (Just <$> action) `catchError` f

fromMaybeAction :: forall e m a. Monad m => ActionT e m (Maybe a) -> a -> ActionT e m a
fromMaybeAction action a = fromMaybe a <$> action

mapActionT :: forall e m1 m2 a. (forall b. m1 b -> m2 b) -> ActionT e m1 a -> ActionT e m2 a
mapActionT f = mapExceptT g
where g = mapReaderT h
h = mapStateT f
2 changes: 1 addition & 1 deletion src/Yue/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Yue.Internal.Type.Error (AppError)

import Effect.Aff (Aff) as Aff
import Effect.Aff.Class (class MonadAff, liftAff) as Aff
import Yue.Internal.Type.Action (ActionT) as E
import Yue.Internal.Type.Action (ActionT, mapActionT) as E

import Yue.Server.Body (json, json', setJson, setText, tryJson) as E
import Yue.Server.Control (finish, throw, throwE) as E
Expand Down

0 comments on commit 888fa1f

Please sign in to comment.