Sure but from like, a mental point of view? Do I copy parser state over and over again until I have all the data I need?
In mutable version I would create a mutable object and push data one after the other. If it was just an array id probably use some kind of reducer, BUT…
If I’m reading a stream, how do I reduce it? Let’s say I have a file that consists of chunks, each chunk starts with a header where there is chunk type and body length, if type is equal to a type I need - I need to parse data, if not - skip based on length.
you have a data structure that represents where you are in the stream and the intermediate result of the parse
parsing is then a matter of constructing a new structure that represents the next position in the stream etc