'how can I do a switchMap and get the diferent responses in the subscription?

How can I achieve the following using RXJS? I have 3 requests each dependant on the previous, and I need all responses in the subscription.

this.httpService.request1(paramsObj).pipe(
    switchMap((response)=>{
        return this.httpService.request2({...response})
    }),
    switchMap((response)=>{
        return this.httpService.request3({...response})
    })
).subscribe(([response1, response2, response3]) => {
   // somehow access all responses here while each response is dependeant on the previous one
})


Solution 1:[1]

You probably have to mannually pass it down like below

this.httpService.request1(paramsObj).pipe(
    switchMap((res1)=>{
        return this.httpService.request2({...res1}).pipe(map(res2=>[res1,res2]))
    }),
    switchMap(([res1,res2)=>{
        return this.httpService.request3({...res2}).pipe(map(res3=>[res1,res2,res3]))
    })
).subscribe(([res1, res2, res3]) => {

})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fan Cheung