如果你正在尋找一個point free
某種風格,這個怎麼樣的方法:
const R = require('ramda');
// sample data
const data = [{name: 'rod', age: 25}, {name: 'chuck', age: 30}, {name: 'rod', age: 50}];
// Alternative 1: bake in the name and vary the data
const filterByName = R.compose(R.filter, R.propEq('name'));
const filterByRod = filterByName('rod');
// now supply the data
filterByRod(data); // => [ { name: 'rod', age: 25 }, { name: 'rod', age: 50 } ]
// Alternative 2: bake in the data, and then vary the name
const filterDataByName = R.compose(R.partialRight(R.filter, [data]), R.propEq('name'));
// now supply the name
filterDataByName('rod'); // => [ { name: 'rod', age: 25 }, { name: 'rod', age: 50 } ]
相信你的目標是什麼上述方案2在你的問題。
是的,你是v.close--你希望部分應用過濾器,但是自從數據到最後,你可以使用R.partialRight - http://ramdajs.com/0.22.1/docs/#partialRight – arcseldon