mirror of
https://github.com/lexi-lambda/freer-simple.git
synced 2024-12-24 14:43:57 +03:00
Add asks function same as Control.Monad.Reader.
This commit is contained in:
parent
41d43f07ce
commit
f711144f83
@ -24,6 +24,7 @@ module Control.Monad.Freer.Reader (
|
||||
Reader(..),
|
||||
|
||||
ask,
|
||||
asks,
|
||||
runReader,
|
||||
local
|
||||
) where
|
||||
@ -38,6 +39,10 @@ data Reader e v where
|
||||
ask :: (Member (Reader e) r) => Eff r e
|
||||
ask = send Reader
|
||||
|
||||
-- | Request a value from the environment and applys as function
|
||||
asks :: (b -> a) -> Eff '[Reader b] a
|
||||
asks f = ask >>= return . f
|
||||
|
||||
-- | Handler for reader effects
|
||||
runReader :: Eff (Reader e ': r) w -> e -> Eff r w
|
||||
runReader m e = handleRelay return (\Reader k -> k e) m
|
||||
|
Loading…
Reference in New Issue
Block a user