Is there a way to keep track of a value with pipeable operators?
To give a tangible example, let's say that I want to :
Over a data stream S:
Then merge these and exploit the objects I created.
Basically,
const data = from([1, 2, 3]).pipe(
// Memorize here
map(a => req1(a)),
flatMap(a => a),
map(b => syncOp(b)),
map(c => req2(c)),
flatMap(d => d),
map(e => ({id: _memorized_, value: e}))
merge(data).subscribe(f => console.log(f.id, f.value))
Any input on the matter will be greatly appreciated.
Note: If possible, I'd prefer not to carry the value I need all the way down via the creation of an object at the top.
You can easily do that by just restructuring your operators and making memorized
a local variable:
const data = from([1, 2, 3]).pipe(
// Memorize here
mergeMap(memorized => req1(memorized).pipe(
flatMap(a => a),
map(b => syncOp(b)),
map(c => req2(c)),
flatMap(d => d),
map(e => ({id: memorized, value: e}))
));
merge(data).subscribe(f => console.log(f.id, f.value));