import { filter, map, withLatestFrom, type Observable, type ObservableInput, type OperatorFunction, } from 'rxjs'; export function ifLatestFrom( input: ObservableInput, condition: (inputResult: O, sourceResult: T) => boolean, ): OperatorFunction { return (source: Observable) => { return source.pipe( withLatestFrom(input), filter(([sourceResult, inputResult]) => condition(inputResult, sourceResult)), map(([a]) => a), ); }; }