• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript ramda.filter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: includes

export const sampleForletter = (letter: string) => (
  collection: string[],
  count: number,
  replacement = false
): string[] => {
  const suitableWords = R.filter(startsWith(letter), collection);

  let words = sample<string>(suitableWords, count, replacement);
  words = [
    ...words,
    ...sample<string>(
      R.filter(
        word => !startsWith(letter)(word) && includes(letter)(word),
        collection
      ),
      count - words.length
    )
  ];
  words = [
    ...words,
    ...sample<string>(
      R.filter(
        word => !startsWith(letter)(word) && !includes(letter)(word),
        collection
      ),
      count - words.length
    )
  ];

  return words;
};
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:31,代码来源:helpers.ts


示例2: switch

		.map(([claims, title]) => {
			switch (title) {
				case PENDING_CLAIM:
					return R.filter((n: any) => n.status == STATUS_SUBMITTED || n.status == STATUS_DRAFT || n.status == STATUS_REJECTED)(claims);

				case CLOSED_CLAIM:
					return R.filter((n: any) => n.status == STATUS_APPROVED)(claims);

				default:
				  return claims;
			}
		});
开发者ID:simbiosis-group,项目名称:ion2-claim,代码行数:12,代码来源:claim-list.ts


示例3: filter

  /**
   * Return a filtered array of records
   *
   * Example
   *
   * ```
   * this.list = Array.filter(this.searchText, ['invoiceCode', 'customer', 'description'], this._data);
   * ```
   */
  static filter(query, fields, array) {
    if (query) { query = query.toLowerCase() }

    if(array == null || query === '') { return array }
    let arr = array;
    const filterByFields = obj => {
      let toFilter = false;

      fields.forEach(field => {
        if (!toFilter) {
          if (R.is(Object, field)) {
            const key = R.head(R.keys(field));
            const value = R.values(field);
            if (key === 'eq') {
              toFilter = (obj[value] === query);
            }
          } else {
            if (!R.isNil(obj[field])) {
              toFilter = obj[field].toString()
                .toLowerCase().indexOf(query) > -1
            }
          }
        }
      });
      return toFilter;
    };

    return R.filter(filterByFields, array);
  }
开发者ID:simbiosis-group,项目名称:ion2-helper,代码行数:38,代码来源:array-helper.ts


示例4: exec

    exec('git branch --no-color -a', options, (error, stdout, stderr) => {
      if (stderr || error) return reject(stderr || error);

      const getCurrentBranch = R.compose(
        R.trim,
        R.replace('*', ''),
        R.find(line => line.startsWith('*')),
        R.split('\n')
      );

      const processBranches = R.compose(
        R.filter(br => stdout.match(new RegExp(`remotes\/.*\/${br}`))),
        R.uniq
      );

      const currentBranch = getCurrentBranch(stdout);
      const branches = processBranches([currentBranch, defaultBranch]);

      return excludeCurrentRevision
        ? resolve(branches)
        : getCurrentRevision(exec, projectPath)
            .then((currentRevision) => {
              return resolve(branches.concat(currentRevision));
            });
    });
开发者ID:d4rkr00t,项目名称:vscode-open-in-github,代码行数:25,代码来源:common.ts


示例5: sendSubscriptions

    /**
     * Sends all subscribed values to the Reactotron app.
     *
     * @param node The tree to grab the state data from
     */
    function sendSubscriptions(state: any) {
      // this is unreadable
      const changes = pipe(
        map(when(isNil, always(""))) as any,
        filter(endsWith(".*")),
        map((key: string) => {
          const keyMinusWildcard = slice(0, -2, key)
          const value = dotPath(keyMinusWildcard, state)
          if (is(Object, value) && !isNilOrEmpty(value)) {
            return pipe(keys, map(key => `${keyMinusWildcard}.${key}`))(value)
          }
          return []
        }) as any,
        concat(map(when(isNil, always("")), subscriptions)),
        flatten,
        reject(endsWith(".*")) as any,
        uniq as any,
        sortBy(identity) as any,
        map((key: string) => ({
          path: key,
          value: isNilOrEmpty(key) ? state : dotPath(key, state),
        })),
      )(subscriptions)

      reactotron.stateValuesChange(changes)
    }
开发者ID:nick121212,项目名称:reactotron,代码行数:31,代码来源:reactotron-mst.ts


示例6: findChildImages

export function findChildImages(parentName: string, imagesConfigMap: ImagesConfigMap): string[] {
  const confPairs = toPairs(imagesConfigMap) as [string, ImageConfig][];
  return pipe(
    filter<[string, ImageConfig]>(pathEq(['1', 'baseimage'], parentName)),
    map((arr: [string, ImageConfig]) => arr[0])
  )(confPairs);
}
开发者ID:d6u,项目名称:docker-build-layers,代码行数:7,代码来源:Util.ts


示例7: getNextChild

  public getNextChild(id: string): Optional<ICourseStructure> {
    const entity = this.course.findEntity(id);

    if (!entity) {
      return undefined;
    }

    if ((entity as InternalNode).getChildren()) {
      const children = (entity as InternalNode).getChildren();

      const cmps = [
        ascend(
          (child: AbstractNode) => this.getProgress(child.getId()).progress
        ),
        ascend(
          (child: AbstractNode) => this.getProgress(child.getId()).counter || 0
        )
      ];

      const sortedChildren = stableSortWith(cmps, children);

      const relevantChildren = filter(
        (child: AbstractNode) =>
          this.getProgress(child.getId()).progress < Progress.Correct,
        sortedChildren
      );

      if (relevantChildren.length !== 0) {
        return relevantChildren[0].getInfo() as ICourseStructure;
      }
    }

    return undefined;
  }
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:34,代码来源:CourseInteractor.ts


示例8: castModelKey

export const hiddenComponentDecorator = ({
  modelName,
  fields,
}: {
  modelName: string;
  fields: Fields;
}): { modelName; fields: Fields & WithHidden } => {
  const TAG = '[hiddenComponentDecorator]';
  logger.log(TAG, { fields });

  let wrappedFields = R.omit([castModelKey('createdAt'), castModelKey('updatedAt')])(fields);
  if (R.has('id', wrappedFields)) {
    const hidden = R.isNil(wrappedFields.id.value);
    wrappedFields = R.mergeDeepRight(wrappedFields, { id: { options: { hidden } } });
  }

  const positions = R.filter(R.pathEq(['options', 'type'], 'SortPosition'))(wrappedFields);
  if (!R.isEmpty(positions)) {
    const hiddenPositions = R.map(position => ({
      ...position,
      options: { hidden: true },
    }))(positions);

    wrappedFields = R.mergeDeepRight(wrappedFields, { ...hiddenPositions });
  }
  logger.log(TAG, 'wrappedFields', { wrappedFields }, diff(fields, wrappedFields));
  return { modelName, fields: wrappedFields };
};
开发者ID:danielwii,项目名称:asuna-admin,代码行数:28,代码来源:index.ts


示例9: wrapForeignOpt

export const associationDecorator = ({ modelName, fields }: { modelName: string; fields }) => {
  const TAG = '[associationDecorator]';
  logger.log(TAG, { fields });

  // prettier-ignore
  const associationFields = R.filter(R.compose(R.not, R.isNil, R.prop('associations')))(fields);
  logger.log(TAG, { associationFields }, R.not(R.isEmpty(associationFields)));
  if (R.not(R.isEmpty(associationFields))) {
    const wrapForeignOpt = R.map(opt => ({
      ...opt,
      association: AppContext.adapters.models.getAssociationConfigs(opt.modelName),
    }));
    const withAssociations = R.mapObjIndexed(field => ({
      ...field,
      foreignOpts: wrapForeignOpt(field.foreignOpts),
    }))(associationFields);
    logger.debug(TAG, { withAssociations, wrapForeignOpt });

    const wrappedFields = R.mergeDeepRight(fields, withAssociations);
    logger.debug(TAG, { wrappedFields });

    return { modelName, fields: wrappedFields };
  }

  return { modelName, fields };
};
开发者ID:danielwii,项目名称:asuna-admin,代码行数:26,代码来源:index.ts


示例10: describe

    describe('ramda', function () {

        function filterUserData(username) {
            return R.filter(R.propEq('username', username));
        }

        const isUnComplete = (task) => !task.complete;
        const filterOutstandingTasks = R.pipe(
            R.filter(isUnComplete),
            R.map(R.pick(['id', 'title', 'dueDate', 'priority'])));

        function descSort(property) {
            return (a, b) => a[property].localeCompare(b[property]);
        }

        function getIncompleteTaskSummaries(username) {
            return R.pipeP(fetchTaskData, R.prop('tasks'), filterUserData(username), filterOutstandingTasks, R.sort(descSort('dueDate')));
        }

        it('returns unfinished tasks sorted by due dates in ascending order', function (done) {
            getIncompleteTaskSummaries('Scott')()
                .then((answer) => done(assert.deepEqual(answer, expectedAnswer)))
                .catch((error) => done(error));
        });
    });
开发者ID:dhassaine-scottlogic,项目名称:fp_experiments,代码行数:25,代码来源:ts_ramda.test.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ramda.find函数代码示例发布时间:2022-05-25
下一篇:
TypeScript ramda.evolve函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap