本文整理汇总了TypeScript中transducers-js.comp函数的典型用法代码示例。如果您正苦于以下问题:TypeScript comp函数的具体用法?TypeScript comp怎么用?TypeScript comp使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了comp函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: intoExample
function intoExample () {
var inc = function(n: number) { return n+1; };
var isEven = function(n: number) { return n % 2 == 0; };
var apush = function(arr: number[], x: number) { arr.push(x); return arr; };
var xf = t.comp(t.map(inc),t.filter(isEven));
t.into([], xf, [1,2,3,4]); // [2,4]
}
示例2: catExample
function catExample () {
var reverse = function(arr: number[]) {
var arr: number[] = Array.prototype.slice.call(arr, 0);
arr.reverse();
return arr;
};
var xf = t.comp(t.map(reverse), t.cat);
t.into([], xf, [[3,2,1],[6,5,4]]); // [1,2,3,4,5,6]
}
示例3: it
it('transduces Map without initial values', () => {
let m1 = Map({a: 1, b: 2, c: 3, d: 4});
let xform = t.comp(
t.filter(([k, v]) => v % 2 === 0),
t.map(([k, v]) => [k, v * 2]),
);
let m2 = t.transduce(xform, Map(), m1);
expect(m1.toObject()).toEqual({a: 1, b: 2, c: 3, d: 4});
expect(m2.toObject()).toEqual({b: 4, d: 8});
});
示例4: it
it('transduces Stack with initial values', () => {
const v1 = Stack.of(1, 2, 3);
const v2 = Stack.of(4, 5, 6, 7);
const xform = t.comp(
t.filter(x => x % 2 === 0),
t.map(x => x + 1),
);
const r = t.transduce(xform, Stack(), v1, v2);
expect(v1.toArray()).toEqual([1, 2, 3]);
expect(v2.toArray()).toEqual([4, 5, 6, 7]);
expect(r.toArray()).toEqual([7, 5, 1, 2, 3]);
});