I need to take some more time to think about what you are actually trying to achieve.
But from a very first glimpse I think this would be an application for fold_left or Belt.Array.reduce.
st would probably be your accumulator.
The only possible “issue” I see is, that reduce will go over every item of the array without any possibility for an “early exit”.
Could you give a short description of what your code should be doing in prosa text, please?
The task: think of parsing a markup language with blocks of varying boundaries. While it is possible to keep track of the nesting level and boundary stack, I am trying to do it with recursion instead.
Is that a good application of async/await? (It’s basically a task for a generator).
If you are ultimately targeting node and this is supposed to be more than just a quick sketch, I’d use node streams.
They are quite performant AFAIK and would support arbitary file sizes without holding everything in memory.
There is a package called rescript-node which is maintained by a long-time community member (@spyder), which should give you a kickstart.
You’d probably want to split up parsing and detection of elements from acting on them.
The former would be done by emitting custom events, while the latter would be achieved by subscribing event-handlers to them.