本文整理汇总了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);
}
开发者ID:DallanQ,项目名称:rxjs,代码行数:12,代码来源:reduce.ts
示例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))
);
}
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:7,代码来源:indexes-worker.ts
示例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;
}, {}));
});
开发者ID:MykhailoIskiv,项目名称:rxjs,代码行数:8,代码来源:scan-spec.ts
示例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));
}
开发者ID:vba,项目名称:DecisionTrees,代码行数:10,代码来源:starwars.ts
示例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();
});
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:10,代码来源:reduce-spec.ts
示例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();
});
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:11,代码来源:reduce-spec.ts
示例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}`)));
}
});
开发者ID:paulcbetts,项目名称:spawn-rx,代码行数:11,代码来源:index.ts
注:本文中的rxjs/operators.reduce函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论