Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Loop back observable in RxJS?

This is a bit of a convoluted example, but I was wondering how to do the following in RxJs: After a certain part in the pipeline, feed the value back into an earlier part of the pipeline, so it will get processed again.

of(1, 2, 3, 4, 5).pipe(
  map(x => x + 1),
  map(x => x + 1),
  filter(x => x % 2),
  // refeed after the first map but before the second
)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here's an example of how you might use expand to do this:

function isEven(x) {
  return x % 2 == 0
}

of(1, 2, 3, 4, 5).pipe(
  map(x => x + 1),
  expand(x => of(x).pipe(
    map(x => x + 1),
    filter(isEven)
  ))
);

Here's how you might write a recursive function to do this:

function isEven(x) {
  return x % 2 == 0
}

function loopBack(x : number) {
  return of(x).pipe(
    map(x => x + 1),
    filter(isEven),
    mergeMap(loopBack),
    startWith(x)
  );
}

of(1, 2, 3, 4, 5).pipe(
  map(x => x + 1),
  mergeMap(loopBack),
);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!