Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with a StateT transformator #104

Closed
KommuSoft opened this issue Nov 28, 2022 · 4 comments
Closed

Work with a StateT transformator #104

KommuSoft opened this issue Nov 28, 2022 · 4 comments

Comments

@KommuSoft
Copy link
Contributor

It would be nice if we can also use a StateT monad transformer when walking through the AST and thus keep track of the section, and update the state based on content that we see when "walking" over the tree.

@jgm
Copy link
Owner

jgm commented Nov 28, 2022

walkM in Text.Pandoc.Walk works for any monad. So yes, you can use it with a state monad or something else with StateT. Am I missing something in your question?

@KommuSoft
Copy link
Contributor Author

After rereading, I realized it was missing the most important part: the toJSONFilter which does not seem to allow effectively walk over this.

The implementation looks like

instance (Walkable [a] Pandoc) => ToJSONFilter (a -> IO [a]) where
toJSONFilter f = BL.getContents >>=
(walkM (fmap concat . mapM f) :: Pandoc -> IO Pandoc) .
either error id . eitherDecode' >>=
BL.putStr . encode

so probably generalizing it to any monad transformer with IO as the "outer" one is possible. I will take a look into it.

@jgm
Copy link
Owner

jgm commented Nov 29, 2022

Yes, maybe we could generalize these to any MonadIO instance.
An alternative approach that should work already would be to use the IO Monad and an IORef for state.

@jgm
Copy link
Owner

jgm commented Jan 13, 2023

Closed by #105.

@jgm jgm closed this as completed Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants