A find method has following signiture
find(): Observable<User[]>
It returns an observable that emits a list of users, that may look like this:
[{ user_1 }, { user_2 }]
My goal is to run an async operation on each user from the list. That async operation should modify the element by adding some fields. At the end the list of updated users should be emitted. This is what I have tried:
return this.service.find()
.mergeMap((users: User[]) => Observable.from(users))
.mergeMap((user: User) => {
return this.anotherService.getAdditionalData(user.id)
.map((res: any) => {
// return edited user
})
})
// How to return User[] here?
With the first mergeMap an observable for each user in the list is created. Then for each user observable another async operation is made. The async operation returns the edited user.
My question is, at the end, how can I return the user list with the edited users. Or how can I collect the edited users in a list and return this list?