저는 최근에 fp를 배우려고 노력 중이며 ramda.js를 프로젝트에 사용하려고했지만 몇 가지 문제를 만났습니다.ramda.js와 코드의 차이점은 무엇입니까?
내 코드의 목표는 list
배열의 각 요소에 초기 값이있는 result
받침대를 추가하려고하지만 예상대로 작동하지 않습니다. 내가 Ramda.js를 사용하여주의해야 할 일이
var list = [{name: 'foo'}, {name: 'bar'}, {name: 'baz'}]
var list1 = R.clone(list)
var getResultList = R.times(R.identity)
// what's the difference between them ??
// it worked as expected if I wrap assoc fn into arrow function and transfer it to fn
var mapAssocResult= R.map(e=> R.assoc('result', getResultList(2), e))
// it didn't work as expected if I just transfer it as param of map fn
var mapAssocResult1= R.map(R.assoc('result', getResultList(2)))
list = mapAssocResult(list)
list1 = mapAssocResult1(list1)
list[0].result === list[1].result //false
list1[0].result === list1[1].result // true
// it seems that all result props point to the same array reference, but why?
가 : 여기
내 코드?내 생각에 Ramda.js를 사용하는 것이 완전히 잘못되었으므로 Ramda.js에서 내 목표를 달성하기위한보다 합리적인 방법이 있습니까?
감사합니다.
아래의 Scott Christopher의 제안을 넘어선 진짜 제안은 없지만 'R.range (0)'은 아마도 'Rx (R.identity)'보다 더 구체적이고 분명히 간결합니다. –
제안 해 주셔서 감사합니다. –