With mongodb in node we can use async iterators. Basic example:
const documents: Record<string, any>[] = [];
let cursor = db.collection('randomcollection').find();
for await (let doc of cursor) {
documents.push(document);
}
How does async iterators translate to functional programming, using fp-ts? Is it possible to express the for loop above in fp-ts? I have searched, but found no documentation regarding async iterators.
const whereIamRightNow = pipe(
TE.bindTo('db')(createMongoClientWithEncryption),
TE.bind('cursor', ({ db }) => TE.of(getQueryCursor(dateRange)(db.client))),
// how to async iterate over query cursor and call a processing function for each record?
);