After working on some code, I came up with the following implementation
this.form.valueChanges.pipe(
take(1),
map(val => // doSomething),
exhaustMap(val =>
// someInner observable logic
return of({someValue})
)
).subscribe(finalVal => doSomething());
However, as this code is repeated in multiple components, I wanted to refactor it into an external function.
Here is what I attempted
myExhaust(obs: Observable<any>): Observable<{ someValue: SomeClass }> {
return obs.pipe(
exhaustMap((val) => {
// do some stuff
return of({someValue})
})
);
}
Now, I am unsure of how to integrate this new function back into the original code properly (assuming the function itself is correct).