Hello,
According to the documentation, R.pick
Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.
However, if there is R.applySpec before — it affects its behaviour:
R.pipe(
R.applySpec({
foo: R.prop('foo'),
bar: R.prop('bar'),
}),
R.pick(['foo', 'bar']),
// R.pickBy(R.complement(R.isNil)), // workaround
)({ foo: 'FOO' })
// returns {"bar": undefined, "foo": "FOO"}
// expecting {"foo": "FOO"}
Here it's reproduced in REPL
We can see what's happening here if we split up the two operations:
R.applySpec({
foo: R.prop('foo'),
bar: R.prop('bar'),
})({foo: 'FOO'})
// {foo: 'FOO', bar: undefined}
R.pick(['foo', 'bar'])( {foo: 'FOO', bar: undefined} )
//The same as the input
So because applySpec actually _adds in_ the bar property, it's then picked up by pick.
If you're looking for something to remove properties if their value is undefined you could use R.reject(isNil)(obj).
`reject will remove any item matching the predicate, which should take care of your edge case here.
undefined is such a strange value in JS. If null was the billion-dollar mistake, it is at least an understandable version of, "hey, we all know that there's no value here". undefined is billion-shrug mistake: "hey, I dunno, we can pretend it's this value if you like..."
Oh, ok, I can see why I made a wrong assumption.
Most helpful comment
undefinedis such a strange value in JS. Ifnullwas the billion-dollar mistake, it is at least an understandable version of, "hey, we all know that there's no value here".undefinedis billion-shrug mistake: "hey, I dunno, we can pretend it's this value if you like..."