var arr = [1, 2, 3, 4]; var plusOne = x => x + 1; arr.map(plusOne) // [2, 3, 4, 5]
事实上,所有的map方法都可以基于reduce...// 变形运算 var plusOne = x => x + 1; // 累积运算 var append = function (newArr, x) { newArr.push(x); return...newArr; }; R.transduce(R.map(plusOne), append, [], arr); // [2, 3, 4, 5]
上面代码中,plusOne是变形操作,append...= x => x + 1; var square = x => x * x; R.transduce( R.map(R.pipe(plusOne, square)), append,...前面例子中,R.map(plusOne)返回的就是一个 Transformer 对象。
事实上,任何一个对象只要遵守 Transformer 协议,就是 Transformer 对象。