How to use the adjust function from ramda

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

18
19
20
21
22
23
24
25
26
  user => Buffer.from(user).toString('base64')
);

const updateHeaderWithUser = R.compose(
  R.unnest,
  R.adjust(0, getUserHeader),
  R.values,
  R.pick(['user', 'header'])
);
fork icon303
star icon0
watch icon2

22
23
24
25
26
27
28
29
30
31
// Update
const update = Action.caseOn({ // action -> model -> model
  Add: (model) => R.evolve({items: R.append(Component.init(0))}, model),
  Reverse: R.evolve({items: R.reverse}),
  Modify: (idx, counterAction, model) => R.evolve({
    items: R.adjust(Component.update(counterAction), idx)
  }, model)
})

// View
fork icon92
star icon0
watch icon0

33
34
35
36
37
38
39
40
41
42
43
44
45
// https://ramdajs.com/docs/#adjust
console.log('\n=== adjust ===');


console.log(R.adjust(1, R.subtract(__, 10), [100, 200, 300]));


const adjustSubtract = R.adjust(__, R.subtract(__, 10));
const uncurryAdjustSubtract = R.uncurryN(2, adjustSubtract);


console.log(adjustSubtract(1)([100, 200, 300]));
console.log(uncurryAdjustSubtract(1, [100, 200, 300]));
fork icon0
star icon0
watch icon0

+ 2 other calls in file

1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
 *         the element at index `idx` replaced with the value
 *         returned by applying `fn` to the existing element.
 * @see R.update
 * @example
 *
 *      R.adjust(R.add(10), 1, [0, 1, 2]);     //=> [0, 11, 2]
 *      R.adjust(R.add(10))(1)([0, 1, 2]);     //=> [0, 11, 2]
 */
var adjust = _curry3(function adjust(fn, idx, list) {
    if (idx >= list.length || idx < -list.length) {
fork icon0
star icon0
watch icon0

+ 53 other calls in file

88
89
90
91
92
93
94
95
96
97
getFirstRole: player => R.prop('role', R.find(inf => !inf.revealed, player.influence)),

swapRole_s: (oldRole, newRole) => State.get().chain(player => {
  const idx = R.findIndex(R.equals({role: oldRole, revealed: false}), player.influence);
  if (idx == -1) raiseError(`Player does not have role ${oldRole}`);
  return State.put(R.evolve({influence: R.adjust(idx, R.assoc('role', newRole))}, player));
}),

lens: idx => {
  // Context -> Player
fork icon0
star icon0
watch icon0

+ 6 other calls in file

30
31
32
33
34
35
36
37
38
39
40
41
//     [1,2,3,4,5]
//   )
// )


const arr = [1,2,3,4,5]
const Add2 = R.adjust(1,R.add(2),arr)
console.log(Add2)


console.log(
  R.filter(
fork icon0
star icon0
watch icon0

+ 2 other calls in file

319
320
321
322
323
324
325
326
327
*         returned by applying `fn` to the existing element.
* @see R.update
* @example
*
*      R.adjust(1, R.toUpper, ['a', 'b', 'c', 'd']);      //=> ['a', 'B', 'c', 'd']
*      R.adjust(-1, R.toUpper, ['a', 'b', 'c', 'd']);     //=> ['a', 'b', 'c', 'D']
* @symb R.adjust(-1, f, [a, b]) = [a, f(b)]
* @symb R.adjust(0, f, [a, b]) = [f(a), b]
*/
fork icon0
star icon0
watch icon2

+ 19 other calls in file

68
69
70
71
72
73
74
75
76
77
if (isValidData(updates)) {
  const index = R.findIndex(R.propEq('id', id), items);
  if (R.equals(index, -1)) {
    throw new Error('Item not exists');
  }
  items = R.adjust(
    index,
    R.compose(
      R.assoc('updatedAt', new Date().toISOString()),
      R.mergeLeft(updates)
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)