Personally, I find the concepts of monads and data processing very interesting. A couple years ago, I’ve read a paper somewhere about “monadic parser combinators”. It intrigued me and I’ve experimented with the idea a lot. My initial idea was identical in regards of the return value.
It makes sense in terms of “logic” to return the extracted value and the rest, but in terms of performance it does not. It appears that string slicing is way slower than just working with an index. Well at least in nodejs that is.
Though the index approach requires a slightly different function signature to remain pure, which unfortunately makes it less as elegant to use in return.
I’ve clobbered this typescript library together, later with the help from Claude (shameless self-plug: https://github.com/sovrin/unitas). It is typed to a degree (recursions are hit or miss) and should have every function one might need.