-
-
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.
Ref #525
- Loading branch information
Showing
4 changed files
with
81 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 { curry, identical, all } from 'ramda'; | ||
|
||
/** | ||
* Returns true if all items in the list are equivalent to user provided value using `R.identical` for equality comparisons. | ||
* | ||
* @func allIdenticalTo | ||
* @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.allIdentical|allIdentical} | ||
* @example | ||
* | ||
* RA.allIdenticalTo(1, [ 1, 2, 3, 4 ]); //=> false | ||
* RA.allIdenticalTo(1, [ 1, 1, 1, 1 ]); //=> true | ||
* RA.allIdenticalTo([]); //=> true | ||
* RA.allIdenticalTo({}, [ {}, {} ]); //=> false | ||
* | ||
*/ | ||
const allIdenticalTo = curry((val, list) => all(identical(val), list)); | ||
|
||
export default allIdenticalTo; |
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,49 @@ | ||
import { assert } from 'chai'; | ||
|
||
import * as RA from '../src'; | ||
|
||
describe('allIdenticalTo', function() { | ||
context('given all items are identical', function() { | ||
specify('returns true', function() { | ||
assert.isTrue(RA.allIdenticalTo(4, [4, 4, 4, 4])); | ||
}); | ||
}); | ||
|
||
context('given all items are deeply equal', function() { | ||
specify('should return true', function() { | ||
assert.isFalse( | ||
RA.allIdenticalTo({ key: 'foo' }, [{ key: 'foo' }, { key: 'foo' }]) | ||
); | ||
}); | ||
}); | ||
|
||
context('given items are not identical', function() { | ||
specify('should return false', function() { | ||
assert.isFalse(RA.allIdenticalTo(1, [1, 1, 2, 1, 1])); | ||
}); | ||
}); | ||
|
||
context('given items have different type', function() { | ||
specify('should return false', function() { | ||
assert.isFalse(RA.allIdenticalTo(1, [1, 1, '1', 1])); | ||
}); | ||
}); | ||
|
||
context('given items are reference to function', function() { | ||
specify('should return true', function() { | ||
const f = () => {}; | ||
assert.isTrue(RA.allIdenticalTo(f, [f, f, f])); | ||
}); | ||
}); | ||
|
||
context('given empty list provided', function() { | ||
specify('should return true', function() { | ||
assert.isTrue(RA.allIdenticalTo(1, [])); | ||
}); | ||
}); | ||
|
||
it('should curry', function() { | ||
assert.isTrue(RA.allIdenticalTo(1, [1, 1])); | ||
assert.isTrue(RA.allIdenticalTo(1)([1, 1])); | ||
}); | ||
}); |