答案 0 :(得分:0)
这里是RxJS的运算符,它将作为数组对[outer, inner]
发出外部值和内部值。
这是switchMap()
的变体。
export function withSwitchMap<T, R>(inner: (T) => Observable<R>): OperatorFunction<T, [T, R]> {
return (source: Observable<T>): Observable<[T, R]> => {
return source.pipe(
switchMap(a => inner(a).pipe(map(b => [a, b] as [T, R])))
);
}
}
这是mergeMap()
的变体。
export function withMergeMap<T, R>(inner: (T) => Observable<R>): OperatorFunction<T, [T, R]> {
return (source: Observable<T>): Observable<[T, R]> => {
return source.pipe(
mergeMap(a => inner(a).pipe(map(b => [a, b] as [T, R])))
);
}
}