How to use the equals function from ramda
Find comprehensive JavaScript ramda.equals code examples handpicked from public code repositorys.
ramda.equals is a function that compares two values to check if they are equal, using a deep comparison for objects and arrays.
GitHub: curran/gadm-geojson
![curran profile picture](/curran.png?size=40)
5 6 7 8 9 10 11 12 13 14
function lengthZero(list) { return R.equals(0, R.length(list)); } function isStringType(cur) { return R.equals('String', R.type(cur)); } function changeEndPath(folderName, path) { const pathAsArray = R.split('/', path);
+ 3 other calls in file
112 113 114 115 116 117 118 119 120 121 122 123
logger.warn() } function stdoutLineMatches (expectedLine, stdout) { const lines = stdout.split('\n').map(R.trim) const lineMatches = R.equals(expectedLine) return lines.some(lineMatches) }
How does ramda.equals work?
ramda.equals is a function that takes two arguments and returns a boolean value indicating whether or not they are equal. It uses a deep comparison for objects and arrays, so it will recursively compare all nested properties and elements. When comparing objects, ramda.equals checks if both objects have the same number of properties, and if so, it recursively compares each property. For two properties to be considered equal, their names must match and their values must be equal according to ramda.equals. When comparing arrays, ramda.equals checks if both arrays have the same number of elements, and if so, it recursively compares each element. For other types of values, such as strings, numbers, or booleans, ramda.equals uses the standard === operator to compare them. ramda.equals also supports comparing cyclical objects and objects with circular references by detecting and breaking cycles. In summary, ramda.equals provides a deep comparison function that can compare objects and arrays for equality.
5826 5827 5828 5829 5830 5831 5832 5833 5834 5835
* @param {*} b * @return {Boolean} * @example * * R.equals(1, 1); //=> true * R.equals(1, '1'); //=> false * R.equals([1, 2, 3], [1, 2, 3]); //=> true * * var a = {}; a.v = a; * var b = {}; b.v = b;
+ 107 other calls in file
28 29 30 31 32 33 34 35 36 37 38
const validateDomainData = validate({ name: { reason: 'The name of the file is invalid. It must be lowercased, alphanumeric and each component must be more than 2 characters long', fn: or([ R.equals('@'), and([ R.is(String), R.compose( R.all(or([
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
const R = require("ramda"); const obj1 = { name: "Alice", age: 30, address: { street: "123 Main St", city: "Anytown", state: "CA", }, }; const obj2 = { name: "Alice", age: 30, address: { street: "123 Main St", city: "Anytown", state: "CA", }, }; const obj3 = { name: "Bob", age: 25, address: { street: "456 Elm St", city: "Othertown", state: "NY", }, }; console.log(R.equals(obj1, obj2)); // true console.log(R.equals(obj1, obj3)); // false
In this example, ramda.equals is used to compare two objects, obj1 and obj2, which have the same structure and values. The comparison returns true, indicating that the two objects are equal. ramda.equals is also used to compare obj1 and obj3, which have different values for their properties. In this case, the comparison returns false, indicating that the two objects are not equal.
GitHub: octachrome/t2
108 109 110 111 112 113 114 115 116 117 118
const Game = { isOver: R.pipe( R.prop('players'), R.reject(Player.isDead), R.length(), R.equals(1)), opponents: game => R.pipe( R.prop('players'), R.addIndex (R.map) (R.pair),
+ 6 other calls in file
GitHub: dqmmpb/define-demos
201 202 203 204 205 206 207 208 209 210 211 212 213
log(R.contains(4)([1, 2, 3, 5])); log(R.contains([42])([[42]])); log(R.contains({name: 'Fred'})([{name: 'Fred'}])); var equals3 = R.equals(3); log(R.all(equals3)([3, 3, 3, 3])); log(R.all(equals3)([3, 3, 1, 3])); var lessThan0 = R.flip(R.lt)(0);
+ 19 other calls in file
36 37 38 39 40 41 42 43 44 45 46 47
const charToGene = x => geneMap[x] // Gene -> Char const geneToChar = x => { const y = Object.entries(geneMap) .find(([_, v]) => R.equals(x, v)) return y ? y[0] : 'n/a' } // Chromosome -> [Gene]
+ 2 other calls in file
19 20 21 22 23 24 25 26 27 28 29
); const isBinaryOperator = (selector, argumentNodes) => R.and( isSelectorBinaryOperator(selector), R.equals( R.length(argumentNodes), 1 ), R.complement(
+ 3 other calls in file
375 376 377 378 379 380 381 382 383
* @return {Boolean} `true` if the predicate is satisfied by every element, `false` * otherwise. * @see R.any, R.none, R.transduce * @example * * const equals3 = R.equals(3); * R.all(equals3)([3, 3, 3, 3]); //=> true * R.all(equals3)([3, 3, 1, 3]); //=> false */
+ 27 other calls in file
GitHub: octachrome/t2
65 66 67 68 69 70 71 72 73 74 75 76 77
Game.isOver = R.pipe( R.prop('players'), R.reject(Player.isDead), R.length(), R.equals(1)); Game.checkOver = R.when(Game.isOver, R.set(State.lens, {id: State.GAME_OVER})); Game.nextTurn = game => R.pipe(
+ 3 other calls in file
269 270 271 272 273 274 275 276 277 278
const structure = getStructure(currentDocumentsPath, config) const maxFiles = structure?.maxFiles ? structure.maxFiles : 0 const filesLeft = maxFiles - documents.length const filterDocs = () => documents.filter((doc) => { return R.equals(doc.field_document_path.path, currentDocumentsPath) }) if (!currentDocumentsPath || !currentDocumentsPath.length) { return null
64 65 66 67 68 69 70 71 72 73 74
* @param {string[]} keys1 * @param {string[]} keys2 */ const compareKeys = (keys1, keys2) => R.all( R.equals(true), R.zipWith((x, y) => x === y, keys1, keys2) ); /**
7 8 9 10 11 12 13 14 15 16 17
* * @function * @param {String} value The string to compare * @returns {Boolean} `true` if `value` equals `/`; `false` otherwise. */ const equalsSlash = equals('/'); /** * Forces the given `path` to start with and remove any trailing * `/` (slash character).
GitHub: cberube/AoC-2022
15 16 17 18 19 20 21 22 23 24 25
x => x.replace(/[^0-9]/g, '') ) const leastCommonMultiple = (values) => { const allEqual = ar => R.all( R.equals(R.head(ar)), R.tail(ar) ) const firstValues = [...values]
37 38 39 40 41 42 43 44 45 46
html: userNotificationDetails.messages.email.message, subject: userNotificationDetails.messages.email.subject }) ], [ R.equals('fcm'), () => Fcm.send({ token: mode.to, body: userNotificationDetails.messages.fcm.formattedBody, data: userNotificationDetails.details.data,
54 55 56 57 58 59 60 61 62 63
mandatoryMasks = defaultTo([1])(mandatoryMasks); additionalMasks = defaultTo([1])(additionalMasks); negativeMasks = defaultTo([0])(negativeMasks); const maskCheckPositiveFunc = userMask => gt(userMask & mask, 0); const maskCheckNegativeFunc = userMask => equals(userMask & mask, 0); const mandatoryMasksResult = ifElse( is(Object), userMasks => all(maskCheckPositiveFunc, userMasks),
+ 3 other calls in file
ramda.clone is the most popular function in ramda (30311 examples)