Ramda R.pickBy R.identity包括零0' s

时间:2018-02-07 15:13:56

标签: javascript optimization ramda.js

简单的问题,如何管道pickBy标识并包含值为零的props。目前这个例子会省略零

let linkType = { 
    name: 'zac',
    money: 0,
    problems: 'as much as the money'
}
let linksList = R.pipe(
                    R.pickBy(R.identity),
                  )(linkType);

1 个答案:

答案 0 :(得分:3)

如果值等于0,则使用R.eitherR.equal(0)获取true,如果不是,则使用R.identity的结果:

const linkType = {
  name: 'zac',
  money: 0,
  problems: 'as much as the money',
  another: false
}

const linksList = R.pickBy(R.either(R.equals(0), R.identity))(linkType);

console.log(linksList);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>