-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #525
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { all, equals, curry } from 'ramda'; | ||
|
||
/** | ||
* Returns true if all items in the list are equivalent to user provided value using `R.equals` for equality comparisons. | ||
* | ||
* @func allEqualTo | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.11.0|v2.11.0} | ||
* @category List | ||
* @sig a -> [b] -> Boolean | ||
* @param {*} val User provided value to check the `list` against | ||
* @param {Array} list The list of values | ||
* @return {boolean} | ||
* @see {@link RA.allEqual|allEqual}, {@link https://ramdajs.com/docs/#equals|equals} | ||
* @example | ||
* | ||
* RA.allEqualTo(1, [ 1, 2, 3, 4 ]); //=> false | ||
* RA.allEqualTo(1, [ 1, 1, 1, 1 ]); //=> true | ||
* RA.allEqualTo({}, [ {}, {} ]); //=> true | ||
* RA.allEqualTo(1, []); //=> true | ||
* | ||
*/ | ||
const allEqualTo = curry((val, list) => all(equals(val), list)); | ||
|
||
export default allEqualTo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { assert } from 'chai'; | ||
import * as R from 'ramda'; | ||
|
||
import * as RA from '../src'; | ||
|
||
// https://github.com/ramda/ramda/pull/1992 | ||
const hasFunctionReferenceEqualityBug = (() => { | ||
const f = () => {}; | ||
return R.uniq([f, f, f]).length !== 1; | ||
})(); | ||
|
||
describe('allEqualTo', function() { | ||
context('given all items are equal', function() { | ||
specify('returns true', function() { | ||
assert.isTrue(RA.allEqualTo(4, [4, 4, 4, 4])); | ||
}); | ||
}); | ||
|
||
context('given all items are deeply equal', function() { | ||
specify('should return true', function() { | ||
assert.isTrue( | ||
RA.allEqualTo({ key: 'foo' }, [{ key: 'foo' }, { key: 'foo' }]) | ||
); | ||
}); | ||
}); | ||
|
||
context('given items are not equal', function() { | ||
specify('should return false', function() { | ||
assert.isFalse(RA.allEqualTo(1, [1, 1, 2, 1, 1])); | ||
}); | ||
}); | ||
|
||
context('given items have different type', function() { | ||
specify('should return false', function() { | ||
assert.isFalse(RA.allEqualTo(1, [1, 1, '1', 1])); | ||
}); | ||
}); | ||
|
||
if (!hasFunctionReferenceEqualityBug) { | ||
context('given items are reference to function', function() { | ||
specify('should return true', function() { | ||
const f = () => {}; | ||
assert.isTrue(RA.allEqualTo(f, [f, f, f])); | ||
}); | ||
}); | ||
|
||
context( | ||
'given items are same functions without the same reference', | ||
function() { | ||
specify('should return false', function() { | ||
const getF = () => () => {}; | ||
assert.isFalse(RA.allEqualTo(getF(), [getF(), getF(), getF()])); | ||
}); | ||
} | ||
); | ||
} | ||
|
||
context('given empty list provided', function() { | ||
specify('should return true', function() { | ||
assert.isTrue(RA.allEqualTo(1, [])); | ||
}); | ||
}); | ||
|
||
it('should curry', function() { | ||
assert.isTrue(RA.allEqualTo(1, [1, 1])); | ||
assert.isTrue(RA.allEqualTo(1)([1, 1])); | ||
}); | ||
}); |