( Stackblitz | jsBin | jsFiddle )
// RxJS v6+
import { every } from 'rxjs/operators';
import { of } from 'rxjs';
// 发出5个值
const source = of(1, 2, 3, 4, 5);
const example = source.pipe(
// 每个值都是偶数吗?
every(val => val % 2 === 0)
);
// 输出: false
const subscribe = example.subscribe(val => console.log(val));
( Stackblitz | jsBin | jsFiddle )
// RxJS v6+
import { every } from 'rxjs/operators';
import { of } from 'rxjs';
// 发出5个值
const allEvens = of(2, 4, 6, 8, 10);
const example = allEvens.pipe(
// 每个值都是偶数吗?
every(val => val % 2 === 0)
);
// 输出: true
const subscribe = example.subscribe(val => console.log(val));
- every 📰 - 官方文档
📁 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/every.ts