Could I skip all subsequent operators chain if condition is truthy in RxJS

a_zatula

Is it possible in RxJS 5.5 to implement condition using some operator to skip all subsequent operators and emit some value (false)? For instance in this ng service method I would bypass bunch of this .map chain and provide false value immediately if response.length === 0:

getProjectDrivers(projectId): Observable<any> {
  return this.http.get('someUrl').pipe(
    // if (response.length === 0) { return false; and skip whole operator chain bellow}
    map((response: ProjectDriver[]) => response.filter((projectDriver: ProjectDriver) => projectDriver.streamName !== "AllRevenueStreamTotals")),
    map((response: ProjectDriver[]) => command => ({})
  )
)
.catch(this.handleError);

}

Eliseo

I suppose you always can play with switchMap

  return this.http.get('someUrl').pipe(
    switchMap(response => {
      if (!response.length) {
        return of(null);
      } else {
        return of(result).pipe(
          map((response: ProjectDriver[]) => response.filter((projectDriver: ProjectDriver) => projectDriver.streamName !== "AllRevenueStreamTotals")),
          map((response: ProjectDriver[]) => command => ({}))
        )
      }
    }
  )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why can I omit the subsequent null-conditional operators in an invocation chain?

How to skip a particular index from a loop if a condition is truthy in React?

How can I easily make Github Actions skip subsequent jobs execution on certain condition?

Why am I obtaining this error when I try to chain 2 map() RxJS operators into a pipe()?

How can I chain multiple dependent subscriptions using rxjs operators and transformations?

How do I update a variable and all subsequent variables once a certain condition is met in R?

Rxjs pipe function with multiple filter() and switchMap() operators in the chain

How to chain switchMap-operators with function bodies in rxjs 6

Looking for RxJs Operator that returns early, skipping operators below, not filter() or skip()

RXJS Stop propagation of Observable chain if certain condition is met

Promise with nodejs, how could I chain results

In IntelliJ, how to auto-import rxjs operators from 'rxjs/operators' i.s.o. 'rxjs/internal/operators'?

How could I create Cold Subject in RxJS?

Align subsequent ternary operators in PhpStorm

Python Addition and Subtraction with subsequent operators

Using rxjs in angular 2 component, should I manually import the operators?

How can I avoid multiple nested subscriptions using RxJS operators?

How do I persist a value across RxJS 6 pipe operators?

How can I chain RxJS observable in a redux-observable epic?

RxJava operators or Kotlin chain

/windowApache Flink chain operators

How to chain Ternary Operators?

How do modified condition operators work? SQL - ALL and ANY

How could i drop rows in Pandas in condition?

How to skip promise in a chain

Should I include all the interfaces in the inheritance chain?

How could i skip a row if a csv field is empty

Chaining rxjs operators

Importing lettable RxJS operators