I can see two ways to implement this. The tricky part is that flux::read_at needs both the sequence and the cursor, so we cannot simply do .find_if(...).read(). Adding a reference to the sequence in the cursor would be counter productive.
read_*
This solution is the most obvious. For each collector, we can provide a read_ version that will convert the cursor to an optional. We could also make the default collectors (find_if, ...) return an optional, and create cursor_* versions instead
read_self (tap?)
Another solution would be to provide a generic read_self collector. It could be used like this:
Description
Currently,
flux::first
,flux::find_if
and some others return acursor
. I will call these functions collectorsThis makes sense with flux iteration model, but is unwieldy in practice:
What I would like instead is having an optional:
Proposed solution
I can see two ways to implement this. The tricky part is that
flux::read_at
needs both the sequence and the cursor, so we cannot simply do.find_if(...).read()
. Adding a reference to the sequence in the cursor would be counter productive.read_*
This solution is the most obvious. For each collector, we can provide a
read_
version that will convert the cursor to an optional. We could also make the default collectors (find_if
, ...) return an optional, and createcursor_*
versions insteadread_self
(tap
?)Another solution would be to provide a generic
read_self
collector. It could be used like this:It would mean less implementation effort, but I'm not sure it would be really ergonomic. Also, this might have side effects I did not think about
Something else?
If there is a better way, I'd love to hear about it
Sidenote: while writing this, I've noticed
find_if
doesn't seem tested?