import { checkFunctionOrProperty } from "../_check" import { Source } from "../_core" import { In, Out, Predicate } from "../_interfaces" import { makeObservable } from "../_obs" import { Transaction } from "../_tx" import { curry2 } from "../_util" import { dispatcherOf, Observable } from "../Observable" import { isProperty, Property } from "../Property" import { Operator } from "./_base" import { filter } from "./filter" import { skipUntil } from "./skipUntil" import { startWith } from "./startWith" export const skipWhile: CurriedSkipWhile = curry2(_skipWhile) export interface CurriedSkipWhile { ( f: Predicate | Property, observable: In, ): Out (f: Predicate | Property): ( observable: In, ) => Out } function _skipWhile(f: Predicate | Property, observable: Observable): Observable { checkFunctionOrProperty(f) return isProperty(f) ? skipUntil(filter(x => !x, startWith(true, f)), observable) : makeObservable(observable, new SkipWhile(dispatcherOf(observable), f)) } class SkipWhile extends Operator { private pass: boolean = false constructor(src: Source, private f: Predicate) { super(src) } public next(tx: Transaction, val: T): void { const { f } = this if (this.pass || (this.pass = !f(val))) { this.sink.next(tx, val) } } }