How to use the reject function from ramda

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

ramda.reject is a function in the Ramda library that returns a new list with all the elements that satisfy a predicate function removed.

76
77
78
79
80
81
82
83
84
85

const view = R.curry((action$, model) => {
  const hasTodos = model.todos.length > 0,
        left = R.length(R.reject(R.prop('done'), model.todos)),
        filteredTodos = model.view === 'all'    ? model.todos
                      : model.view === 'active' ? R.reject(R.prop('done'), model.todos)
                                                : R.filter(R.prop('done'), model.todos)
  return h('section.todoapp', [
    h('header.header', [
      h('h1', 'todos'),
fork icon92
star icon0
watch icon2

221
222
223
224
225
226
227
228
229
230
    btok.token.push({
      dups: extra.quantity === "∞" ? 0 : extra.quantity || 1,
      flip: true,
    });
  }),
  R.reject(R.propEq("quantity", 0))
)(game.tokens || []);
let tokenHeight = 30 * ((game.companies || []).length + tokens.length);

json.tray.push(btok);
fork icon52
star icon51
watch icon0

How does ramda.reject work?

ramda.reject is a function in the Ramda library that returns a new list with all the elements that satisfy a predicate function removed. The function takes two arguments: a predicate function and a list of values. The predicate function takes a single value and returns a Boolean value indicating whether that value should be removed from the resulting list. When ramda.reject is called, it applies the predicate function to each element in the input list. If the predicate function returns true for an element, that element is removed from the resulting list. If the predicate function returns false for an element, that element is included in the resulting list. For example, the following code uses ramda.reject to remove all even numbers from a list of integers: javascript Copy code {{{{{{{ const R = require('ramda'); const numbers = [1, 2, 3, 4, 5, 6]; const odds = R.reject((n) => n % 2 === 0, numbers); console.log(odds); // Output: [ 1, 3, 5 ] In this example, we use ramda.reject to create a new list odds that contains only the odd numbers from the input list numbers. The function applies the predicate function (n) => n % 2 === 0 to each element in numbers. For even numbers, the predicate function returns true, and those elements are removed from the resulting list. For odd numbers, the predicate function returns false, and those elements are included in the resulting list. Overall, ramda.reject is a useful utility function for creating a new list with elements removed based on a specified predicate function.

9
10
11
12
13
14
15
16
17
18
19
20
const SLIDES_PATH = join(__dirname, './slides.md');


const isMdFile = name => name.includes('.md');
const folders = pipe(
    unary(readdirSync),
    reject(isMdFile)
);


const makeVerticalSliders = src => {
    const slides = readdirSync(src);
fork icon4
star icon5
watch icon0

25
26
27
28
29
30
31
32
33
34
    const {target} = val
    return { id, index, target }
})

// filter choices without target
const hasTarget = R.reject(R.propEq('target', null))

// filter choice that is on hold
const notSelected = (selected) => R.reject((choice) => {
    return selected !== null
fork icon1
star icon4
watch icon2

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const R = require("ramda");

const students = [
  { name: "Alice", grade: "A" },
  { name: "Bob", grade: "B" },
  { name: "Charlie", grade: "C" },
  { name: "David", grade: "D" },
];

const passingStudents = R.reject((student) => student.grade === "D", students);

console.log(passingStudents);
// Output: [ { name: 'Alice', grade: 'A' }, { name: 'Bob', grade: 'B' }, { name: 'Charlie', grade: 'C' } ]

In this example, we use ramda.reject to create a new list passingStudents that contains only the students who received a passing grade (i.e., not a D) from the input list students. The function applies the predicate function (student) => student.grade === 'D' to each element in students. For students with a D grade, the predicate function returns true, and those elements are removed from the resulting list. For students with grades other than D, the predicate function returns false, and those elements are included in the resulting list. Overall, ramda.reject is a useful utility function for creating a new list with elements removed based on a specified predicate function.

17
18
19
20
21
22
23
24
25
26
27
)(defaults)


const mergeString = R.unapply(R.compose(
  R.defaultTo(''),
  R.head(),
  R.reject(isUseless),
  R.reverse,
  R.drop(1)
))

fork icon0
star icon4
watch icon0

64
65
66
67
68
69
70
71
72
73
  R.map(lintComponent),
  (p) => Promise.all(p),
  R.andThen(
    R.pipe(
      R.map(logReport),
      R.reject(R.equals(false)),
      R.unless(R.isEmpty, () => process.exit(1)),
    ),
  ),
);
fork icon0
star icon2
watch icon0

144
145
146
147
148
149
150
151
152
153
        return newTransaction;
    }
}

removeBlockTransactionsFromTransactions(newBlock) {
    this.transactions = R.reject((transaction) => { return R.find(R.propEq('id', transaction.id), newBlock.transactions); }, this.transactions);
    this.transactionsDb.write(this.transactions);
}

checkBlock(newBlock, previousBlock, referenceBlockchain = this.blocks) {
fork icon0
star icon1
watch icon0

14
15
16
17
18
19
20
21
22
23
    this.taskId = 1;
}

mine(rewardAddress, feeAddress, nodeId, totalNodes, ts) {
    let baseBlock = Miner.generateNextBlock(rewardAddress, feeAddress, this.blockchain);
    process.execArgv = R.reject((item) => item.includes('debug'), process.execArgv);

    // Emit new mine request
    this.blockchain.emitter.emit('newMineRequest', baseBlock, this.taskId, ts);
    this.newMineRequest(baseBlock, this.taskId, nodeId, totalNodes);
fork icon0
star icon1
watch icon0

-2
fork icon0
star icon1
watch icon0

+ 3 other calls in file

24
25
26
27
28
29
30
31
32
33
34
  };
}


function findValidFiles(source, transformers) {
  return R.pipe(
    R.reject(shouldBeIgnore),
    R.filter(R.either(isDirectory, isValidFile(transformers))),
    R.chain((filename) => {
      if (isDirectory(filename)) {
        const subFiles = fs.readdirSync(filename)
fork icon0
star icon0
watch icon1

+ 2 other calls in file

17
18
19
20
21
22
23
24
25
26
  }
  return handler(opts);
}

/* Returns a rejector fn to exclude seed keywords from results. */
const rejectKeywords = (seeds) => R.reject((kw) => R.contains(kw, seeds));

/*
* Return the most common keywords among the given apps.
*/
fork icon0
star icon0
watch icon0

49
50
51
52
53
54
55
56
57
58
const bankFacts = [...citiFacts, ...mvcuFacts, ...mvcuOldFacts, ...venmoFacts];
const existingIds = {};
resolve(R.compose(
  R.reverse,
  R.sortBy(R.prop('timestamp')),
  R.reject(R.isNil),
  R.map((fact) => {
    const id = computeFactId(fact);
    if (existingIds[id]) {
      logger.error(`Duplicate ${fact.account} ids in input: ${JSON.stringify(fact)}`);
fork icon0
star icon0
watch icon0

6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
 *
 *      var isOdd = (n) => n % 2 === 1;
 *
 *      R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]
 *
 *      R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}
 */
var reject = _curry2(function reject(pred, filterable) {
    return filter(_complement(pred), filterable);
});
fork icon0
star icon0
watch icon0

+ 35 other calls in file

57
58
59
60
61
62
63
64
65
66
67
68


const Player = {
  // Player -> Number
  countInf: R.pipe(
    R.prop('influence'),
    R.reject(R.propEq('revealed', true)),
    R.length),


  // Player -> Boolean
  hasNInf: R.curry((n, player) => Player.countInf(player) == n),
fork icon0
star icon0
watch icon0

+ 13 other calls in file

85
86
87
88
89
90
91
92
93
94
//  warnIgnoredTopLevel :: {*} -> {*}
var warnIgnoredTopLevel = R.tap(R.pipe(
  R.chain(R.ifElse(R.propEq('type', 'VariableDeclaration'),
                   R.prop('declarations'),
                   R.of)),
  R.reject(R.either(isModuleExportsExpr, isRequireExpr)),
  R.map(function(ast) {
    return 'Top-level declaration `' + ast.id.name +
      '` ignored in ' + ast.loc.source + ':' + ast.loc.start.line;
  }),
fork icon0
star icon0
watch icon0

75
76
77
78
79
80
81
82
83

const r = row(cave, R.head(blocked))

const nextDropX = R.compose(
  R.head,
  R.reject(R.compose(isBlocked, R.last)),
  R.converge(R.zip, [R.identity, R.map(R.nth(R.__, r))]),
  R.converge(Array.of, [R.dec, R.inc]),
)(startPoint[0])
fork icon0
star icon0
watch icon0

+ 2 other calls in file

58
59
60
61
62
63
64
65
66
67
const remove = (id) => {
  const itemDeleted = R.find(R.propEq('id', id), items);
  if (!itemDeleted) {
    throw new Error('Item not exist');
  }
  items = R.reject(R.propEq('id', id), items);
  return itemDeleted;
};

const update = (id, updates) => {
fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
15
      apiUtils = require('../../utils/api');


// https://platform.aliencreations.com/api/v1/public/keys/productPlatform,customerPlatform
router.get('/keys/:services?', (req, res, next) => {
  const services = R.compose(
    R.reject(R.isEmpty),
    R.split(','),
    R.pathOr('', ['params', 'services'])
  )(req);

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)