How to use the clone function from ramda

Find comprehensive JavaScript ramda.clone code examples handpicked from public code repositorys.

ramda.clone creates a deep copy of an object or an array in JavaScript.

28
29
30
31
32
33
34
35
36
37
38
39
const buildNodeMap = (nodes) => {
    return nodes.reduce((acc, element) => { return acc.set(element.properties.resourceId, element) }, new Map());
};


const translateHierarchy = (hierarchy, inKeys, nodeMap, filterMap) => {
    let keys = R.clone(inKeys);


    if (keys.length === 0) {
        return hierarchy.nodes.map(element => {
            element.type = "node";
fork icon65
star icon619
watch icon41

281
282
283
284
285
286
287
288
289
290
}
// 1.extract codebase path and runtime
let skillJson = fs.readJSONSync(skillJsonPath, "utf-8");
if (skillJson.skillManifest) {
  // some templates still use "skillManifest" which is the v0 manifest structure
  skillJson.manifest = R.clone(skillJson.skillManifest);
  skillJson = R.omit(["skillManifest"], skillJson);
}
const apisCustom = R.view(R.lensPath(["manifest", "apis", "custom"]), skillJson);
const lambdaResources = R.view(R.lensPath(["deploy_settings", profile, "resources", "lambda"]), v1Config);
fork icon50
star icon139
watch icon0

+ 19 other calls in file

How does ramda.clone work?

ramda.clone is a function that creates a deep copy of a given object or array by recursively copying all of its properties or elements, making it possible to manipulate the copied object or array without modifying the original one. Internally, ramda.clone uses a combination of Object.create and Object.assign to create a new object with the same prototype and copy all properties of the original object to it, or it uses Array.from to create a new array with the same elements as the original one.

38
39
40
41
42
43
44
45
46
47
};
httpClient.request(options, "GET_ACCESS_TOKEN", this.config.doDebug, (err, response) => {
  if (err) {
    return callback(err);
  }
  const tokenBody = R.clone(response.body);
  if (tokenBody.error) {
    return callback(new CliError(tokenBody.error));
  }
  tokenBody.expires_at = this._getExpiresAt(tokenBody.expires_in).toISOString();
fork icon50
star icon139
watch icon0

145
146
147
148
149
150
151
152
153
154
155
  });
}


function _assembleAskResources(userInput, profile) {
  const askResourcesJson = R.clone(AskResources.BASE);
  const askStatesJson = R.clone(AskStates.BASE);
  const askProfileResources = {skillMetadata: userInput.skillMeta};
  const askProfileStates = {skillId: userInput.skillId};
  if (userInput.skillCode) {
    askProfileResources.code = userInput.skillCode;
fork icon50
star icon139
watch icon0

Ai Example

1
2
3
4
5
6
7
const R = require("ramda");

const original = { a: 1, b: 2, c: 3 };
const cloned = R.clone(original);

console.log(cloned); // { a: 1, b: 2, c: 3 }
console.log(cloned === original); // false

In this example, ramda.clone is used to create a deep copy of the original object. The cloned object is created using R.clone(original), and the result is logged to the console. Note that cloned is a separate object from original, and modifying one does not affect the other.

46
47
48
49
50
51
52
53
54
55
  currentMode = symbol;
}
if (isElement(symbol)) {
  if (currentMode === 'new' && (currentAction === 'modify' ||
                                currentAction === 'delete')) {
    oldElement = R.clone(currentElement);
    currentElement = attrs;
    currentElement.old = oldElement;
  } else {
    currentElement = attrs;
fork icon12
star icon31
watch icon48

+ 9 other calls in file

15
16
17
18
19
20
21
22
23
24
function deepDotEquals(obj1, obj2) {
  const paths = _enumeratePaths(obj1);
  const pathsWithEquals = paths.filter(
    (p) => typeof R.path(p, obj1).equals === "function"
  );
  let obj1Clone = R.clone(obj1);
  let obj2Clone = R.clone(obj2);
  for (const p of pathsWithEquals) {
    if (!R.path(p, obj1).equals(R.path(p, obj2))) {
      throw new Error(`mismatch using .equals method of path ${p.join(".")}`);
fork icon10
star icon11
watch icon0

261
262
263
264
265
266
267
268
269
270
271
272
			process.on('unhandledRejection', exit);
		}
	}


	getConfig() {
		return clone(this.configuration.config);
	}
}


// Export public API
fork icon5
star icon9
watch icon0

323
324
325
326
327
328
329
330
331
332
333
334
function isArray (val) {
  return Array.isArray(val)
}


function clone$1 (val) {
  return R.clone(val)
}


function trim$1 (val) {
  return R.trim(val)
fork icon2
star icon5
watch icon3

8
9
10
11
12
13
14
15
16
17

const migrationConfigs = [].concat(config.migrations);
const getOptions = R.assoc('connection', config);

const migrate = (migrationConfig) => {
  const options = R.clone(getOptions(migrationConfig));
  options.connection.user = config.migrationsUser || config.user;
  options.connection.password = config.migrationsPassword || config.password;

  const migrationPath = path.resolve(migrationConfig.directory);
fork icon1
star icon6
watch icon0

244
245
246
247
248
249
250
251
252
253
  return newmsg;
}
//
syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
  msg = this.modifyErrorMessage(msg);
  let tmpl = R.clone(bit_tmpl.JSON_BIT_TEMPLATES.Error_Info);

  tmpl.message = msg;
  tmpl.line = parseInt(line)-1;
  tmpl.column = column;
fork icon0
star icon6
watch icon0

+ 11 other calls in file

1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
  // same as article
  this.push_tmpl(ctx, 'button-copy-text', R.clone(JSON_BIT_TEMPLATES.Article_bit));
};
BitmarkListener.prototype.enterLearningpathdetails = function(ctx) { 
  // same as article
  this.push_tmpl(ctx, 'learning-path-details', R.clone(JSON_BIT_TEMPLATES.Article_bit));
};




//BitmarkListener.prototype.exitArticle = function(ctx) {};
fork icon0
star icon6
watch icon0

+ 221 other calls in file

222
223
224
225
226
227
228
229
230
231
    R.innerJoin((a, b) => a.componentName == b.component_id, R.__, allCharts),
    R.filter(x => selected.indexOf(x.ChartId) < 0)
  )(BBOXES);
}
export function deepClone(obj) {
  return R.clone(obj);
}
export function isIe() {
  const uaAutoScroll = navigator.userAgent.toLowerCase();
  return (uaAutoScroll.indexOf('msie') > -1 || uaAutoScroll.indexOf('rv:11') > -1);
fork icon1
star icon0
watch icon0

3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
// binds names to stack values within a phrase of words
'crouch': {
    dt: '[[[S+]F][F]]',
    compose: function (s, pl) {
        var words = toPLOrNull(s === null || s === void 0 ? void 0 : s.pop());
        var argList = r.clone(toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop()));
        if (words !== null && argList) {
            var values = r.map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
            // const localWD: { [index: string]: Word } =
            //     r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
fork icon0
star icon5
watch icon2

+ 9 other calls in file

2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
const res = this.but.remove_close_bracket_and_follow(code);
(this.stk.top()).bit[this.body_key] = (this.stk.top()).bit[this.body_key].replace(code, '');
const key = camelize(what.substr(1));  // remove &
(this.stk.top()).bit[slot] = {};
(this.stk.top()).bit[slot]['type'] = what.substr(1);
(this.stk.top()).bit[slot][key] = key==='video' ? R.clone(JSON_BIT_TEMPLATES.Video) : R.clone(JSON_BIT_TEMPLATES.VideoLink);
let parent = (this.stk.top()).bit[slot][key];

if (key==='video') {
  parent['format'] = url.split('.').pop();
fork icon0
star icon5
watch icon3

+ 8759 other calls in file

67
68
69
70
71
72
73
74
75
76
77
  }
  return R.differenceWith((a, b) => a == b)(R.range(1, 10), Object.keys(notOptions))
}


const solveSudoku = (board) => {
  const solvingBoard = R.clone(board)
  const lookups = toLookups(board)
  const { rows, columns, squares } = lookups
  let iterations = 0
  while (!isComplete(solvingBoard)) {
fork icon1
star icon0
watch icon0

72
73
74
75
76
77
78
79
80
81
  if (symbol === 'nd' && currentElement && currentElement.type === 'relation') {
    currentMember.nodes.push(attrs);
  }

  if (symbol === 'member' && currentElement && currentElement.type === 'relation') {
    currentMember = R.clone(attrs);
    currentMember.nodes = [];
    currentElement.members.push(currentMember);
  }
}
fork icon4
star icon2
watch icon91

+ 3 other calls in file

1062
1063
1064
1065
1066
1067
1068
1069
1070
* @param {*} value The object or array to clone
* @return {*} A deeply cloned copy of `val`
* @example
*
*      const objects = [{}, {}, {}];
*      const objectsClone = R.clone(objects);
*      objects === objectsClone; //=> false
*      objects[0] === objectsClone[0]; //=> false
*/
fork icon0
star icon0
watch icon0

12
13
14
15
16
17
18
19
20
21
22
const flash = (board) => {
  const flashPoints = R.filter(
      (p) => U.get(board, p) >= 10,
      U.getIndicies(board));


  board = R.clone(board);
  const newBoard = R.reduce((board, [i, j]) => {
    board[i][j] = -1;
    return board;
  }, board, flashPoints);
fork icon0
star icon0
watch icon0

5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
 * @param {*} value The object or array to clone
 * @return {*} A new object or array.
 * @example
 *
 *      var objects = [{}, {}, {}];
 *      var objectsClone = R.clone(objects);
 *      objects[0] === objectsClone[0]; //=> false
 */
var clone = _curry1(function clone(value) {
    return value != null && typeof value.clone === 'function' ? value.clone() : _clone(value, [], [], true);
fork icon0
star icon0
watch icon1

+ 18 other calls in file

83
84
85
86
87
88
89
90
91
92
    throw new Error('Update fields are not valid');
  }
};

const list = () => {
  return R.clone(items);
};

return {
  create,
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)