Skip to content

concatMap observables, go to next on error, stop when one completes #7526

Answered by demensky
keithlayne asked this question in Q&A
Discussion options

You must be logged in to vote

I can also suggest this solution:

const END = Symbol();

function concatMapError<I, O>(
  project: (value: I) => Observable<O>
): OperatorFunction<I, O> {
  return pipe(
    concatMap((value) =>
      project(value).pipe(
        endWith(END),
        catchError(() => EMPTY)
      )
    ),
    takeWhile((value): value is O => value !== END)
  );
}

But in my opinion materialize and dematerialize are much clearer.


That's what I did, felt pretty gross. I figured there had to be a better way.

You can always make a completely custom operator that will fully satisfy your specific requirements.


Also this approach seems to have a shortcoming: if you never get a completion from an inner obser…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
3 replies
@keithlayne
Comment options

@demensky
Comment options

Answer selected by keithlayne
@keithlayne
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants