branchAt method
A new trace: this one's own history up to and including step, then
whatever continuation resolves for every step after it and up to
throughStep — a "what if", branched at step without touching this
trace at all. continuation is a plain function rather than a second
DataSourceRegistry because branching is a property of the trace, not
of who is asking for one: the caller already knows which source it
swapped and for what.
Implementation
DataSourceTrace branchAt(
int step,
int throughStep,
Map<String, Object?> Function(int step) continuation,
) {
final branch = DataSourceTrace();
for (var i = 0; i < _steps.length; i++) {
if (_steps[i] > step) break;
branch.record(_steps[i], _values[i]);
}
for (var s = step + 1; s <= throughStep; s++) {
branch.record(s, continuation(s));
}
return branch;
}