skipWhile
function
stable
Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds true, but emits all further source items as soon as the condition becomes false.
skipWhile<T>(predicate: (value: T, index: number) => boolean): MonoTypeOperatorFunction<T>
Parameters
predicate | A function to test each item emitted from the source Observable. |
Returns
MonoTypeOperatorFunction<T>
: A function that returns an Observable that begins emitting items emitted by the source Observable when the specified predicate becomes false.
Description
Skips all the notifications with a truthy predicate. It will not skip the notifications when the predicate is falsy. It can also be skipped using index. Once the predicate is true, it will not be called again.
Example
Using Value: Skip some super heroes
import { from } from 'rxjs'; import { skipWhile } from 'rxjs/operators'; const source = from(['Green Arrow', 'SuperMan', 'Flash', 'SuperGirl', 'Black Canary']) // Skip the heroes until SuperGirl const example = source.pipe(skipWhile((hero) => hero !== 'SuperGirl')); // output: SuperGirl, Black Canary example.subscribe((femaleHero) => console.log(femaleHero));
Using Index: Skip value from the array until index 5
import { from } from 'rxjs'; import { skipWhile } from 'rxjs/operators'; const source = from([1, 2, 3, 4, 5, 6, 7, 9, 10]); const example = source.pipe(skipWhile((_, i) => i !== 5)); // output: 6, 7, 9, 10 example.subscribe((val) => console.log(val));
Overloads
skipWhile(predicate: BooleanConstructor): OperatorFunction<T, Extract<T, Falsy> extends never ? never : T>
Parameters
predicate | Type: |
Returns
OperatorFunction<T, Extract<T, Falsy> extends never ? never : T>
skipWhile(predicate: (value: T, index: number) => true): OperatorFunction<T, never>
Parameters
predicate | Type: |
Returns
OperatorFunction<T, never>
skipWhile(predicate: (value: T, index: number) => boolean): MonoTypeOperatorFunction<T>
Parameters
predicate | Type: |
Returns
MonoTypeOperatorFunction<T>
See Also
© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/skipWhile