Skip to content
Snippets Groups Projects
Commit 1050161c authored by Alice Brenon's avatar Alice Brenon
Browse files

Prove MonadTrans and MonadIO instances to ease composition with useful monads

parent 0f61b7e0
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,8 @@ module GEODE.Metadata.SplitContext
, runSplitT ) where
import Control.Monad.Identity (Identity(..))
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Trans (MonadTrans(..))
import Data.Map as Map (Map, (!?), delete, empty, insert)
import Data.Text (Text)
......@@ -68,6 +70,12 @@ instance Monad m => SplitContext (SplitContextT m) where
context = SplitContextT $ \current -> pure (current, current)
update f = SplitContextT $ \current -> pure ((), f current)
instance MonadTrans SplitContextT where
lift m = SplitContextT $ \current -> m >>= \a -> pure (a, current)
instance MonadIO m => MonadIO (SplitContextT m) where
liftIO = lift . liftIO
next :: SplitContext m => Field a -> m Int
next f@(HeadWord _) = lookupEdit f (Just . maybe 1 (+1)) >>= pure . maybe 0 id
next Page = lookupEdit Page (+1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment