当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ramda.findIndex函数代码示例

本文整理汇总了TypeScript中ramda.findIndex函数的典型用法代码示例。如果您正苦于以下问题:TypeScript findIndex函数的具体用法?TypeScript findIndex怎么用?TypeScript findIndex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了findIndex函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: findIndex

 .reduceRight((updatedArray, el) => {
   /**
    * We need to update in place to maintain the correct timeline of events. Update in-place
    * by finding the index then updating at that index.
    */
   const indexOfFoundEvent = findIndex(({ id }) => id === el.id, updatedArray);
   return indexOfFoundEvent > -1
     ? update(indexOfFoundEvent, el, updatedArray)
     : [el, ...updatedArray];
 }, prevArr)
开发者ID:displague,项目名称:manager,代码行数:10,代码来源:event.helpers.ts

示例2: sum

  // sum :: [Number] → Number
  sum(filed, list) {
    return R.compose(R.sum, R.pluck(filed))(list)
  },
  // pluck :: Functor f => k → f {k: v} → f v
  pluck(filed, list) {
    return R.pluck(filed)(list)
  },
  // filter :: Filterable f => (a → Boolean) → f a → f a
  filter(fn, list) {
    return R.filter(fn, list)
  },
  // findIndex :: (a → Boolean) → [a] → Number
  findIndex(field, val, list) {
    return R.findIndex(R.propEq(field, val))(list)
  },
  // concat :: [a] → [a] → [a]
  concat(listA, listB) {
    return R.concat(listA, listB)
  },
  //flatten :: [a] → [b]
  flatten(list) {
    return R.flatten(list)
  },

  //// [{}] ////
  // getFullObjByField :: k -> [a] -> [a] -> {k:v}
  getFullObjByField(findField, partArr, fullArr) {
    return R.filter(R.where({ [findField]: R.contains(R.__, partArr) }))(fullArr)  // tslint:disable-line
  },
开发者ID:stefaniepei,项目名称:react-redux-scaffold,代码行数:30,代码来源:ramda.ts

示例3: cleanOperators

export function cleanOperators(tokens: IToken[]) {
  const output: IToken[] = [];
  let temp: IToken[] = [];
  let bracketsCount = 0;

  tokens.forEach((token) => {
    const { image } = token;

    if (bracketsCount === 0 && image !== '(' && image !== ')') {
      output.push(token);
      return;
    }

    temp.push(token);
    if (image === '(') {
      bracketsCount += 1;
    } else if (image === ')') {
      bracketsCount -= 1;

      if (bracketsCount === 0) {
        // recursive clean within parenthesis, unnests one layer
        const cleaned = cleanOperators(temp.slice(1, -1));
        if (cleaned.length) {
          // Length check means this is fine
          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
          output.push(R.head(temp)!, ...cleaned, R.last(temp)!);
        }
        temp = [];
      }
    }
  });

  const findFirstRelevant = R.findIndex(
    (token: IToken) => MODULE_REGEX.test(token.image) || token.image === '(',
  );
  const findLastRelevant = R.findLastIndex(
    (token: IToken) => MODULE_REGEX.test(token.image) || token.image === ')',
  );

  const processedTokens = output.slice(findFirstRelevant(output), findLastRelevant(output) + 1);

  const removedDuplicates = processedTokens.filter((item, pos, arr) => {
    // always keep the first and last element
    if (pos === 0 || pos === arr.length - 1) return true;

    // then check if each element is different than the one before it
    return !(AND_OR_REGEX.test(item.image) && AND_OR_REGEX.test(arr[pos + 1].image));
  });

  const moduleTokens = [];
  // Falsy value if array does not contain unique conjunction
  // Need token to inject later on when it is missing between two modules
  const singularConjunction = removedDuplicates.reduce(
    (acc: IToken | null | false, token: IToken) => {
      const { image } = token;
      if (image === 'and' || image === 'or') {
        if (!acc) return token;
        if (acc.image !== image) return false;
      }
      return acc;
    },
    null,
  );

  // Fill in missing values with conjunction found
  for (let i = 0; i < removedDuplicates.length; i++) {
    const token = removedDuplicates[i];
    const nextToken = removedDuplicates[i + 1];
    const isModule = MODULE_REGEX.test(token.image);
    const isAnotherModule = nextToken && MODULE_REGEX.test(nextToken.image);

    moduleTokens.push(token);
    if (singularConjunction && isModule && isAnotherModule) {
      moduleTokens.push(singularConjunction);
    }
  }

  return moduleTokens;
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:79,代码来源:parseString.ts


注:本文中的ramda.findIndex函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。