0

I want to persist some data in StateT monad,

Within Handler of the post(any http method) function I want to modify the data stored in state... but the issue is I can't use State inside Handler...

newtype HandlerM a =  HandlerM (Request -> Response -> Effect Unit -> Aff a)

type Handler = HandlerM Unit

and type of http methods are as follows,

post :: forall r. RoutePattern r => r -> Handler -> App

I want to do something like,

post "/some/api" $ do 
     S.modify (\s -> s { count = s.+ 1}} ---- modify state with respect to response 
     --- handle request

ps: I can use ref but is there any way I can use StateT inside Handler...

1 Answer 1

1

No, you'd have to use a Ref for this - State doesn't work in situations like this.

If you could plumb it through, what would happen is each request being processed would operate in its own State, starting over with the initial value each time.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I have to use Ref no other way around😭

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.