Skip to content

Commit

Permalink
feat: add propNotEq (#275)
Browse files Browse the repository at this point in the history
Closes #238
  • Loading branch information
srghma2 authored and char0n committed Jan 14, 2018
1 parent 45f0a3a commit 82da044
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,17 @@ declare namespace RamdaAdjunct {
from(lens: Function): Function
}

/**
* Returns true if the specified object property is not equal,
* in R.equals terms, to the given value; false otherwise.
*/
propNotEq(prop: string|number, value: any, obj: object): boolean;
propNotEq(prop: string|number, value: any): (obj: object) => boolean;
propNotEq(prop: string|number): {
(value: any, obj: object): boolean;
(value: any): (obj: object) => boolean;
}

/**
* Returns whether or not an object has an own property with the specified name at a given path.
*/
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export { default as lensNotEq } from './lensNotEq';
export { default as lensSatisfies } from './lensSatisfies';
export { default as lensNotSatisfy } from './lensNotSatisfy';
export { default as lensIso } from './lensIso';
export { default as propNotEq } from './propNotEq';
// Logic
export { default as defaultWhen } from './defaultWhen';
export { default as notBoth } from './notBoth';
Expand Down
23 changes: 23 additions & 0 deletions src/propNotEq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { propEq, complement, curryN } from 'ramda';

/**
* Returns true if the specified object property is not equal,
* in R.equals terms, to the given value; false otherwise.
*
* @func propNotEq
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/1.1.0|v1.1.0}
* @category Relation
* @sig String → a → Object → Boolean
* @param {String} prop The prop to pick
* @param {a} value The value to compare to
* @param {Object} object The object, that presumably contains value under the prop
* @return {Boolean} Comparison result
* @see {@link http://ramdajs.com/docs/#propEq|propEq}
* @example
*
* RA.propNotEq('Not you!', 'a', { a: 'foo', b: 'bar' }); //=> true
*/
const propNotEq = curryN(3, complement(propEq));

export default propNotEq;
41 changes: 41 additions & 0 deletions test/propNotEq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as RA from '../src/index';
import eq from './shared/eq';


describe('propNotEq', function() {
let prop;
let value;
let obj;
let expected;

beforeEach(function() {
prop = 'a';
value = 'foo';
obj = { a: 1, b: 2 };
expected = true;
});

it('tests currying', function() {
eq(RA.propNotEq(prop, value, obj), expected);
eq(RA.propNotEq(prop)(value, obj), expected);
eq(RA.propNotEq(prop, value)(obj), expected);
eq(RA.propNotEq(prop)(value)(obj), expected);
});

it('tests prop value is not equal', function() {
eq(RA.propNotEq(prop, value, obj), expected);
});

it('tests prop value is equal', function() {
value = 1;
expected = false;

eq(RA.propNotEq(prop, value, obj), expected);
});

it('tests no prop', function() {
prop = 'bar';

eq(RA.propNotEq(prop, value, obj), expected);
});
});

0 comments on commit 82da044

Please sign in to comment.