I am trying to consume the pages from a pagination in a lazy way so I only retrieve the page when the data is required. Currently, I am stuck using IORef to hold the state of the pages instead of some state monad. One of my problems is that I would like to be able to stream pages or individual items. This causes a clashing of the state if using StateT. polysemy seems like a potential solution but maybe there is a simpler solution Pagination.hs
It sounds like a job for Pipes/conduit/streaming
That way, the information about the state is local to the producer and you don't need any IORef. But I guess it depends a bit on the structure of the rest of the code.
Pipes works well for both one-way and two-way. There might be other reasons to prefer one over the other though. Streamly looks really nice, especially for concurrency and general speed.
I am trying to consume the pages from a pagination in a lazy way so I only retrieve the page when the data is required. Currently, I am stuck using IORef to hold the state of the pages instead of some state monad. One of my problems is that I would like to be able to stream pages or individual items. This causes a clashing of the state if using StateT. polysemy seems like a potential solution but maybe there is a simpler solution Pagination.hs
It sounds like a job for Pipes/conduit/streaming
That way, the information about the state is local to the producer and you don't need any
IORef
. But I guess it depends a bit on the structure of the rest of the code.@Hjulle Thanks, I didn't even think of using pipes
@HateUsernames007 Np :)
Looking at the code, I think more or less all of the IORef boilerplate will disappear with pipes :)
@Hjulle actually looking at the options conduit is probably better since I only need one way and not 2
Thanks for the suggestions. Very helpful
just gonna leave this for completeness: https://hackage.haskell.org/package/streaming-0.2.3.0
there's also https://github.com/composewell/streamly
Georgi Lyubenov // googleson78 said:
oohh, those concurrency features look delicious!!
Check the signature of unfoldM
Fits quite nicely to pagination
https://hackage.haskell.org/package/conduit-1.3.2.1/docs/Data-Conduit-List.html#v:unfoldM
Pipes works well for both one-way and two-way. There might be other reasons to prefer one over the other though. Streamly looks really nice, especially for concurrency and general speed.