biojppm/rapidyaml

Add examples of iterating sequences in quickstart

Opened this issue · 4 comments

Would it be possible to add some examples of iterating sequences in quickstart.cpp? Currently I can only find checks that know ahead of time how many items are in the sequence. From what I've found looking at the code, it seems that the only way to iterate sequences is to use begin() and end() iterators. I'm using the node API btw.

Do you mean these? That's really it; they are written as checks, but that's the way to iterate through a node's children; it doesn't matter whether they are seqs or maps.

Ah, so children works for both seqs and maps. I didn't realize that. Didn't see that mentioned or used anywhere. Maybe it would be nice to mention somewhere in the documentation. I can make a small PR if you think it's a good idea. What do you think?

What gave you the impression that this would be different? Being containers, both seqs and maps can have children.

As for the PR, sure, submit it and let's look at it.

I didn't have much experience with YAML parsers before. The few others that I now took a look at, seem to also treat maps and sequences similarly to rapidyaml. I used rapidjson before, which does handle arrays and objects with separate interfaces, so that's probably where the confusion came from.

I think it would still be beneficial to add example usage of iterating sequences. I found it confusing that there are zero examples of sequences, while there are multiple examples of maps. I will open a PR soonish.