In my case, I could not predict what the final value would be. I also just wanted to find a solution that included simple, simple operators, and I wanted something that I could reuse, so I could not rely on the validity of the values. The only thing I could think of was to define my own operator as follows:
import { pipe, from } from 'rxjs'; import { switchMap, takeWhile, filter, map } from 'rxjs/operators'; export function doWhile<T>(shouldContinue: (a: T) => boolean) { return pipe( switchMap((data: T) => from([ { data, continue: true }, { data, continue: shouldContinue(data), exclude: true } ])), takeWhile(message => message.continue), filter(message => !message.exclude), map(message => message.data) ); }
This is a little strange, but it works for me, and I can import and use it.
Michael pearson
source share