I am using the fp-ts library and I cannot figure out how to implement the following scenario:
- Let's say I have a service with the request method getBooks(shelf, page) and the response looks like this (the request is paginated):
{
totalItems: 100,
perPage: 25,
books:[{...}, ...],
....
}
- So I would like to send an initial request and then calculate the number of pages:
const nrOfPages = Math.ceil(totalItems / perPage);
- And then loop to get the rest of the books as the first request will only provide me the first 25 book items.
Now the struggle is that in the end I would like to collect all the books inside one object. Basically, I want to await the results and flatmap them together. It is also important that the requests should be sequential and use the fp-ts library.
const allBooks [{...},{...},{...}, ...];