本文整理匯總了TypeScript中transducers-js.transduce函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript transduce函數的具體用法?TypeScript transduce怎麽用?TypeScript transduce使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了transduce函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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});
});
示例2: 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]);
});