Unsure how to initialize a value using IOE before running reinterpret in my effect handler function. #229
Unanswered
rmullin7286
asked this question in
Q&A
Replies: 2 comments
-
What exactly do you mean by that? |
Beta Was this translation helpful? Give feedback.
0 replies
-
When I do things like this, I tend to prefer: runApiIO :: (IOE :> es) => Eff (Api : es) a -> Eff es a
runApiIO = do
reinterpret withSession $ \env -> \case
CallEndpoint r -> do
session <- get
resp <- post session r
return $ responseBodyToJson resp
where
withSession m = do
session <- loginWithCredentials
evalState session m I think your problem is just that you forgot to bind the argument in runApiIO :: (IOE :> es) => Eff (Api : es) a -> Eff es a
runApiIO m = do
session <- loginWithCredentials
flip (reinterpret (evalState session)) m $ \env -> \case
CallEndpoint r -> do
session <- get
resp <- post session r
return $ responseBodyToJson resp Something like that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Basically I have an effect of the following form:
Before the effect can be run, I need to call /login with the ApiKey to initialize the session state. Something like
This doesn't seem to work. I notice looking at the source for things like the State effect that they use
unsafeEff_
to initialize mvars and other variables that require IO. I'd rather not have to lean on unsafe calls if I don't have to.Is the recommended way to do this to create a function
loginWithCredentials :: IOE :> es => ApiKey -> Eff es Session
, call that beforehand, and then change runAPIIO to beIOE :> es => Session -> Eff (Api : es) a -> Eff es a
?Beta Was this translation helpful? Give feedback.
All reactions