Reputation: 525
I have an Observable<Project>
that returns an array of objects. I need to filter this array based on an Observable<boolean>
constructed from a request using the ids of the objects.
Something in the lines of the code below, but I need the actual objects at the array, not the array of booleans I currently mapped them too. I guess something in the lines of a zip that I could use after the initial observable has emmited to join both values so I can use them in the filter.
this.projectService.getCurrentUserProjects().pipe(
mergeAll(),
mergeMap((project) => this.getProjectConditions(project.id)),
filter((condition) => condition),
toArray()
)
My current leads here are:
Upvotes: 0
Views: 284
Reputation: 6424
Consider having an inner map
returning both values (Data & Condition) as an array, as demonstrated below:
this.projectService.getCurrentUserProjects().pipe(
mergeAll(),
mergeMap((project) => this.getProjectConditions(project.id).pipe(map(condition => [project, condition]))),
filter(([,condition]) => condition), // <= only destruct second parameter
map(([project]) => project), // <= only destruct first parameter
toArray()
)
Upvotes: 2