I want to combine the following functions a(), b() and c() to get one result.
function a() {
return rx.of(42);
}
function b(value) {
return rx.of(value*2);
}
function c(val1, val2) {
return rx.of({
original: val1,
modified: val2
})
}
These are simplified variants - they would actually be HTTP-requests. The result of a is needed for executing b, a and bs results are preconditions for executing c. The only thing I can think of is just wrapping them all in .subscribe() calls, but that just doesn't look right. Yet I cannot think of a better way to solve this:
// bad
new Observable(observer => {
a().subscribe(
result_a => {
b(result_a).subscribe(
result_b => {
c(result_a, result_b).subscribe(
result_c => {
observer.next(c);
}
)
}
)
}
)
}).subscribe(
result => console.log(result)
)
I do know that there are operators such as pipe, concat and more but I do not know how to apply them in this specific situation where the result of one Observable is still needed for another one that is executed later on. How could I simplify this by using the proper RxJS techniques?