本文整理汇总了TypeScript中rxjs/operators.reduce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reduce函数的具体用法?TypeScript reduce怎么用?TypeScript reduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reduce函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: higherOrderReduce
export function reduce<T, R>(this: Observable<T>, accumulator: (acc: R, value: T, index?: number) => R, seed?: R): Observable<R> {
// providing a seed of `undefined` *should* be valid and trigger
// hasSeed! so don't use `seed !== undefined` checks!
// For this reason, we have to check it here at the original call site
// otherwise inside Operator/Subscriber we won't know if `undefined`
// means they didn't provide anything or if they literally provided `undefined`
if (arguments.length >= 2) {
return higherOrderReduce(accumulator, seed)(this);
}
return higherOrderReduce(accumulator)(this);
}
示例2: filterAny
function filterAny(values, getter) {
return of(...values).pipe(
map(x => getter(x)),
reduce((a, b) => a.union(b), new TypedFastBitSet()),
map(mask => results => results.intersection(mask))
);
}
示例3: type
type('should accept R typed reducers', () => {
let a: Observable<{ a: number; b: string }>;
a.pipe(reduce<{ a?: number; b?: string }>((acc, value) => {
value.a = acc.a;
value.b = acc.b;
return acc;
}, {}));
});
示例4: getTrainingSet
async function getTrainingSet() {
const peopleArray = await of(...range(5, 10), 2)
.pipe(map(x => `https://swapi.co/api/people/?format=json&page=${x}`))
.pipe(flatMap(x => Axios.get(x).catch(console.error)))
.pipe(map((x: AxiosResponse) => x.data))
.pipe(reduce((acc: any[], x: any) => [x, ...acc], []))
.toPromise();
console.log(JSON.stringify(peopleArray, null, 2));
}
示例5: type
type('should accept T typed reducers when T is an array', () => {
let a: Observable<number[]>;
const reduced = a.pipe(reduce((acc, value) => {
return acc.concat(value);
}, []));
reduced.subscribe(rs => {
rs[0].toExponential();
});
});
示例6: it
it('should reduce with index with seed', (done: MochaDone) => {
const idx = [0, 1, 2, 3, 4, 5];
range(0, 6).pipe(reduce((acc, value, index) => {
expect(idx.shift()).to.equal(index);
return value;
}, -1)).subscribe(null, null, () => {
expect(idx).to.be.empty;
done();
});
});
示例7: merge
proc.on('close', (code: number) => {
noClose = true;
let pipesClosed = merge(stdoutCompleted!, stderrCompleted!)
.pipe(reduce((acc) => acc, true));
if (code === 0) {
pipesClosed.subscribe(() => subj.complete());
} else {
pipesClosed.subscribe(() => subj.error(new Error(`Failed with exit code: ${code}`)));
}
});