pagination - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

HateUsernames007

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

Hjulle

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.

HateUsernames007

@Hjulle Thanks, I didn't even think of using pipes

Hjulle

@HateUsernames007 Np :)
Looking at the code, I think more or less all of the IORef boilerplate will disappear with pipes :)

HateUsernames007

@Hjulle actually looking at the options conduit is probably better since I only need one way and not 2

HateUsernames007

Thanks for the suggestions. Very helpful

Georgi Lyubenov // googleson78

there's also https://github.com/composewell/streamly

Beautiful Streaming, Concurrent and Reactive Composition (Haskell) - composewell/streamly
Torsten Schmits

Georgi Lyubenov // googleson78 said:

there's also https://github.com/composewell/streamly

oohh, those concurrency features look delicious!!

Mats Rauhala

Check the signature of unfoldM

Fits quite nicely to pagination

Hjulle

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.