How to use the findIndex function from ramda

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

297
298
299
300
301
302
303
304
305
306
307
308
function propOr$1 (defaultValue, key, obj) {
  return R.propOr(defaultValue, key, obj)
}


function findIndex$1 (list, fn) {
  return R.findIndex(fn)(list)
}


function keys (val) {
  return Object.keys(val)
fork icon2
star icon5
watch icon3

4
5
6
7
8
9
10
11
12
13
14
15
16
const pluginsLens = lensProp('plugins')


const getPluginIndex = curry((constructorName, { plugins }) => {
  const isMatch = ({ constructor: { name } }) => name === constructorName


  return findIndex(isMatch, plugins)
})


const injectPluginIndex = curry((constructorName, fn, config) => {
  const i = getPluginIndex(constructorName, config)
fork icon2
star icon5
watch icon0

+ 3 other calls in file

4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
            var word = toPLOrNull(next_pl[def_i - 2]);
            var key = toStringOrNull(r.head(toArrOrNull(next_pl[def_i - 1])));
            next_pl.splice(def_i - 2, 3); // splice is particularly mutant
            next_wd = defineWord(next_wd, key, { "compose": word });
        }
        def_i = r.findIndex(function (word) { return word === 'compose'; }, next_pl);
    }
    return [next_pl, r.mergeRight(coreWords, next_wd)];
};

fork icon0
star icon5
watch icon2

+ 9 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13


const makeMarkerFinder = (length) =>
  R.pipe(
    parseText,
    R.aperture(length),
    R.findIndex(R.pipe(R.countBy(R.identity), R.values, R.all(R.equals(1)))),
    R.add(length),
  )


const part1 = makeMarkerFinder(4)
fork icon0
star icon1
watch icon0

+ 2 other calls in file

104
105
106
107
108
109
110
111
112
113
114
115
116
};


function findTitledItemIndex(title, items) {
  const strPropStartsWith = R.pipe(R.prop('str'), R.toLower(), R.startsWith(`${R.toLower(title)}:`));


  return R.findIndex(strPropStartsWith, items);
}


function findTitledItem(title, items) {
  const strPropStartsWith = R.pipe(R.prop('str'), R.toLower(), R.startsWith(`${R.toLower(title)}:`));
fork icon0
star icon1
watch icon0

+ 3 other calls in file

71
72
73
74
75
76
77
78
79
80
  .map(JSON.stringify)

// Note the add 1 step to adjust from 0-based to 1-based indices
const dividerIndices = dividerList
  .map(JSON.stringify)
  .map(packet => R.findIndex(R.equals(packet), sortedLines))
  .map(R.add(1))
  .reduce(R.multiply, 1)

console.log(dividerIndices)
fork icon0
star icon0
watch icon0

2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
 * @see R.transduce
 * @example
 *
 *      var xs = [{a: 1}, {a: 2}, {a: 3}];
 *      R.findIndex(R.propEq('a', 2))(xs); //=> 1
 *      R.findIndex(R.propEq('a', 4))(xs); //=> -1
 */
var findIndex = _curry2(_dispatchable('findIndex', _xfindIndex, function findIndex(fn, list) {
    var idx = 0;
    var len = list.length;
fork icon0
star icon0
watch icon0

+ 35 other calls in file

72
73
74
75
76
77
78
79
80
adjustCash: dcash => R.evolve({cash: R.add(dcash)}),

kill: R.evolve({'influence': R.map(R.assoc('revealed', true))}),

revealRole: R.curry((role, player) => {
  const idx = R.findIndex(R.equals({role: role, revealed: false}), player.influence);
  if (idx == -1) raiseError(`Player does not have role ${role}`);
  return R.evolve({influence: R.adjust(idx, R.assoc('revealed', true))}, player);
}),
fork icon0
star icon0
watch icon0

+ 20 other calls in file

780
781
782
783
784
785
786
787
788
789
790
791


const negativeToValueCurried = R.curry(negativeToValue);


function insertCOGSRecord(cogsList, cogsToInsert) {
    const idx = R.pipe(
        R.findIndex((cogs) => (cogs.date_from >= cogsToInsert.date_from)),
        negativeToValueCurried(cogsList.length)
    )(cogsList)
    const mergedList = R.insert(idx, cogsToInsert, cogsList)
    return R.mapAccumRight(setDateAsPrevious, -1, mergedList)[0]
fork icon0
star icon0
watch icon0

+ 2 other calls in file

8
9
10
11
12
13
14
15
16
17
function detectMarker(data) {
  /*
  const words = R.aperture(4, data)
  const uniqueCounts = R.compose(
    R.add(4),
    R.findIndex(R.equals(4)),
    R.map(R.compose(R.length, R.uniq)),
  )(words)
  */

fork icon0
star icon0
watch icon0

7
8
9
10
11
12
13
14
15
16
  }
  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));
const dist = (banks, index) => distStep(setIndex(index, 0)(banks), nextStep(banks, index), banks[index]);
const distMax = (banks) => dist(banks, findMaxIndex(banks));
fork icon0
star icon0
watch icon0

156
157
158
159
160
161
162
163
164
165
const updateAuthors = req.body.authors;

return new Promise((resolve, reject) => {
  if (!R.isEmpty(updateArticles) && R.length(updateArticles) > 0) {
    R.map((update) => {
      const indexArticles = R.findIndex(R.propEq("id", update.id))(
        articles
      );

      if (indexArticles >= 0) {
fork icon0
star icon0
watch icon0

+ 2 other calls in file

64
65
66
67
68
69
70
71
72
73
  return itemDeleted;
};

const update = (id, updates) => {
  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(
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)