How to use the set function from ramda
Find comprehensive JavaScript ramda.set code examples handpicked from public code repositorys.
80 81 82 83 84 85 86 87 88 89
* Create field if path does not exist. * @param {string} pathArray * @param {string} newValue */ setProperty(pathArray, newValue) { this.content = R.set(R.lensPath(pathArray), newValue, this.content); } /** * Write file according to the file path and serialize it based on file extname
50
139
40
+ 4 other calls in file
GitHub: alexa/ask-cli
161 162 163 164 165 166 167 168 169 170 171
}, }; } return { askResources: R.set(R.lensPath(["profiles", profile]), askProfileResources, askResourcesJson), askStates: R.set(R.lensPath(["profiles", profile]), askProfileStates, askStatesJson), }; } /**
50
139
0
GitHub: alexa/ask-cli
47 48 49 50 51 52 53 54 55 56 57 58
} function setupProfile(awsProfile, askProfile) { const homeConfigPath = path.join(os.homedir(), ".ask", "cli_config"); const homeConfig = fs.readJSONSync(homeConfigPath); const updatedConfig = R.set(R.lensPath(["profiles", askProfile, "aws_profile"]), awsProfile, homeConfig); fs.writeJSONSync(homeConfigPath, updatedConfig); } function resolveVendorId(profile) {
50
139
0
GitHub: 0xjjpa/github-patterns
292 293 294 295 296 297 298 299 300 301
// projects.filter(isFrom2016) // ) languages = function languages(projectArray) { return R.reduce(function (accum, project) { return R.set(languageLens(project), R.view(languageLens(project), accum) ? R.view(languageLens(project), accum).concat(project) : [].concat(project), accum); }, {}, projectArray); }; projectsByLanguages = languages(projects.filter(isFrom2016));
6
57
4
+ 3 other calls in file
GitHub: dmcquay/katas
21 22 23 24 25 26 27 28 29 30
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(".")}`); } obj1Clone = R.set(R.lensPath(p), undefined, obj1Clone); obj2Clone = R.set(R.lensPath(p), undefined, obj2Clone); } expect(obj1Clone).to.eql(obj2Clone); }
10
11
0
84 85 86 87 88 89 90 91 92 93
} }, ) const manifestWithIds = idMappings.reduce((acc, idMapping) => { return R.set(R.lensPath(idMapping.keyPath), idMapping.id, acc) }, manifest) const manifestStr = JSON.stringify(JSON.stringify(manifestWithIds)) const unevalManifest = idMappings.reduce((acc, idMapping) => {
2
9
0
GitHub: corporatepiyush/es6
241 242 243 244 245 246 247 248 249 250
_.view(xLens, { x: 1, y: 2 }) //=> 1 _.set(xLens, 4, { x: 1, y: 2 }) //=> {x: 4, y: 2} _.over(xLens, _.negate, {
1
2
0
+ 5 other calls in file
28 29 30 31 32 33 34 35 36 37 38
const concatArraysByPath = doArrayByPath(R.concat); // reversedConcatArraysByPath :: String -> Array -> Object -> Object const reversedConcatArraysByPath = doArrayByPath(data => R.concat(R.__, data)); // setByPath :: String -> Object -> Object -> Object const setByPath = R.curry((objPath, data, object) => R.set(lensStringPath(objPath), data, object) ); // setOutput :: Object -> Object -> Object const setOutput = setByPath('output');
0
2
0
49 50 51 52 53 54 55 56 57 58 59
function filesToTreeStructure(files, sources) { const cleanedSources = sources.map(source => source.replace(/^\.?(?:\\|\/)/, '')); const filesTree = files.reduce((subFilesTree, filename) => { const propLens = R.lensPath(getPropPath(filename, cleanedSources)); return R.set(propLens, filename, subFilesTree); }, {}); return filesTree; }
0
0
1
+ 2 other calls in file
4047 4048 4049 4050 4051 4052 4053 4054 4055 4056
* @see R.prop, R.lensIndex, R.lensProp * @example * * var xLens = R.lensProp('x'); * * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} * R.set(xLens, 8, {x: 1, y: 2}); //=> {x: 8, y: 2} */ var set = _curry3(function set(lens, v, x) { return over(lens, always(v), x);
0
0
0
+ 107 other calls in file
8826 8827 8828 8829 8830 8831 8832 8833 8834 8835
* * const xHeadYLens = R.lensPath(['x', 0, 'y']); * * R.view(xHeadYLens, {x: [{y: 2, z: 3}, {y: 4, z: 5}]}); * //=> 2 * R.set(xHeadYLens, 1, {x: [{y: 2, z: 3}, {y: 4, z: 5}]}); * //=> {x: [{y: 1, z: 3}, {y: 4, z: 5}]} * R.over(xHeadYLens, R.negate, {x: [{y: 2, z: 3}, {y: 4, z: 5}]}); * //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]} */
0
0
2
+ 23 other calls in file
GitHub: octachrome/t2
71 72 73 74 75 76 77 78 79 80 81 82 83
Game.checkOver = R.when(Game.isOver, R.set(State.lens, {id: State.GAME_OVER})); Game.nextTurn = game => R.pipe( R.evolve({whoseTurn: turn => (turn + 1) % game.players.length}), R.set(State.lens, {id: State.START_OF_TURN}) ) (game); Game.opponents = game => R.pipe( R.prop('players'),
0
0
0
+ 7 other calls in file
GitHub: jcla1/AdventOfCode
70 71 72 73 74 75 76 77 78 79
const leftNeighbourNum = getNeighbour(n, path, 0); const rightNeighbourNum = getNeighbour(n, path, 1); const ep = view(path, n); // zero out the stub we are exploding n = R.set(R.lensPath(path), 0, n); if (!R.equals(leftNeighbourNum, [])) { n = R.over(R.lensPath(leftNeighbourNum), R.add(ep[0]), n); }
0
0
0
+ 7 other calls in file
GitHub: akx/advent-of-code-2017
5 6 7 8 9 10 11 12 13 14
result[result.length] = pair[0]; pair = fn(pair[1], result); } return result; }); const setIndex = (index, value) => R.set(R.lensIndex(index), value); const incrIndex = (index) => R.over(R.lensIndex(index), R.inc); const findMaxIndex = (arr) => R.findIndex(R.equals(R.reduce(R.max, 0, arr)))(arr); const nextStep = (banks, index) => (index + 1) % banks.length; const distStep = (banks, index, remaining) => (remaining <= 0 ? banks : distStep(incrIndex(index)(banks), nextStep(banks, index), remaining - 1));
0
0
0
ramda.clone is the most popular function in ramda (30311 examples)