and_then support in simdjson_result for monadic operations
Borrowing the idea of and_then from std::optional / std::expected, error handling for parsing multiple fields can be easy as it can be chained.
simdjson::ondemand::object o; o[key1].and_then(...).and_then(...);
Instead of checking for error twice in the case above.
We already support chaining in our main API (on demand). Screenshot from our documentation:
We do not support chaining arbitrary lambda expressions, although it could be added with ease if there is a use case for it.
I think that chaining refers wrt to nesting of the fields but another way could be to parse fields at the same level of nesting.
I maybe wrong but there's no simple exception free way to check for error without checking each field.
{"a":1, "b":2}
If I want to parse a and then b, I have to check for error twice in each step. With and_then, it's easier as you can focus on error free path and handle errors at last.
One way is to have a variable for each key and then use get() in succession but feels terse than just using and_then