2 回答
TA贡献1864条经验 获得超6个赞
用 不太可能pipe,因为后续函数是一元的(它们将前一个函数的结果作为参数)。一个汇聚功能有助于在这里我想!
const log = (user, location) => {
console.log(`${user.name} is in ${location}`);
};
const getUserData = () => ({ name: 'Giuseppe' });
const getUserLocation = () => 'Bologna';
R.converge(log, [
getUserData,
getUserLocation,
])();
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js" integrity="sha256-xB25ljGZ7K2VXnq087unEnoVhvTosWWtqXB4tAtZmHU=" crossorigin="anonymous"></script>
TA贡献1816条经验 获得超4个赞
我希望我不会太晚。
const pipedFunction = pipe(
getUserData,
getLocationData,
someFunctionThatNeedBothUserAndLocationData
)(input)
const getLocationData = (userData) => [user, location]
const someFunctionThatNeedBothUserAndLocationData = (arg) => {
const [user, location] = arg;
}
或者
const pipedFunction = pipe(
getUserData,
getLocationData,
someFunctionThatNeedBothUserAndLocationData
)(input)
const getLocationData = (userData) => {user, location}
const someFunctionThatNeedBothUserAndLocationData = (arg) => {
const {user, location} = arg;
}
添加回答
举报