infinitered / ramdasauce

Ramda smothered in saucy helpers.
69 stars 4 forks source link

Invert findByProp #6

Closed maluramichael closed 7 years ago

maluramichael commented 8 years ago

Would be nice to have a function which rejects everything that matches the prop.

import R from 'ramda'

/**
 * Rejects any object in an array by the given property and value.
 *
 * @since v1.0.1
 * @param {prop} (String) The prop to search by.
 * @param {value} (String) The string to search for.
 * @param {source} (Array) The array to search in.
 * @return {Object} The object that matches the search or null if not found.
 * @example
 * RS.rejectByProp('id', 'a', [{id: 'a'}, {id: 'b'}]) //=> {id: 'b'}
 */
const rejectByProp = R.curry(
  (prop, value, source) => R.reject(R.propEq(prop, value))(source)
)

export default rejectByProp
skellock commented 8 years ago

Sounds good! I'm just on vacation now, but I can do this when I get back.

skellock commented 7 years ago

I don't always take a vacation, but when I do, it's 5 months long.

RS.rejectByProp('id', 'a', [{id: 'a'}, {id: 'b'}])
// vs.
R.reject(R.propEq('id, 'a'), [{id: 'a'}, {id: 'b'}])

There's not a whole lot of savings here, so I think I'm going to skip on this one.

When I look back at some of functions that we have already, I do kinda question some of them. Like our findByProp and eqLength.

So I'm trying to stay away from the ones that are just predicate wrappers.

100% appreciate you taking the time to file this issue though.