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

TypeScript fp.sortBy函数代码示例

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

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



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

示例1: curry

export const sortByMap = curry(function(
  mapToSortBy: Record<string, number>,
  listToSort: string[]
): string[] {
  return sortBy(function(listItem) {
    return mapToSortBy[listItem];
  }, listToSort);
});
开发者ID:wikipathways,项目名称:gpml2pvjson-js,代码行数:8,代码来源:gpml-utilities.ts


示例2: flow

 (snippets) => flow([
     map('files'),
     flattenDeep,
     groupBy('language'),
     map((language: string[]) => ({
       language: get('language', head(language)),
       size: size(language)
     })),
     sortBy('size'),
     reverse
   ])(snippets)
开发者ID:Gisto,项目名称:Gisto,代码行数:11,代码来源:snippets.ts


示例3: lowfp

() => {
  const adapterLS = new LocalStorage<DbSchema>("test.json");
  const dbFP = lowfp(adapterLS);
  // Get posts
  const postsFP = dbFP("posts");

  // replace posts with a new array resulting from concat
  // and persist database
  const write: Post[] = postsFP.write(
    concat<Post>({ title: "lowdb is awesome", views: random(0, 5) })
  );

  // Find post by id
  const post: Post | undefined = postsFP(find<Post>({ id: 1 }));

  // Find top 5 fives posts
  const popular: Post[] = postsFP([
    sortBy<Post>("views") as PostsAction,
    take(5) as PostsAction
  ]);

  const filtered: Post[] = dbFP("posts")(filter<Post>({ published: true }));
  const writeAction: Post[] = dbFP("posts").write(concat<Post>({ id: 123 }));
  const writeAction2: string = dbFP(["user", "name"]).write(() => "typicode");

  async () => {
    const adapterAsync = new FileAsync<DbSchema>("test.json");
    const dbAsyncPromise = lowfp(adapterAsync);
    const dbAsync = await dbAsyncPromise;
    const postsWithDefault = dbAsync("posts", [{ title: "baz" }] as Post[]);

    const func: Promise<Post[]> = postsWithDefault.write(post => [
      ...post,
      { title: "another" }
    ]);
  };

  type PostsAction = (posts: Post[]) => Post[];
};
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:39,代码来源:lowdb-tests.ts


示例4: test

 test('Test Basic functionality', async () => {
   expect(
     sortBy(
       'name',
       formatIndexFields(
         [mockAuditbeatIndexField, mockFilebeatIndexField, mockPacketbeatIndexField],
         ['auditbeat', 'filebeat', 'packetbeat']
       )
     )
   ).toEqual(
     sortBy('name', [
       {
         aggregatable: true,
         category: 'base',
         description:
           'Date/time when the event originated. For log events this is the date/time when the event was generated, and not when it was read. Required field for all events.',
         example: '2016-05-23T08:05:34.853Z',
         indexes: ['auditbeat', 'filebeat', 'packetbeat'],
         name: '@timestamp',
         searchable: true,
         type: 'date',
       },
       {
         aggregatable: true,
         category: 'agent',
         description:
           'Ephemeral identifier of this agent (if one exists). This id normally changes across restarts, but `agent.id` does not.',
         example: '8a4f500f',
         indexes: ['auditbeat'],
         name: 'agent.ephemeral_id',
         searchable: true,
         type: 'string',
       },
       {
         aggregatable: true,
         category: 'agent',
         indexes: ['filebeat'],
         name: 'agent.hostname',
         searchable: true,
         type: 'string',
       },
       {
         aggregatable: true,
         category: 'agent',
         description:
           'Unique identifier of this agent (if one exists). Example: For Beats this would be beat.id.',
         example: '8a4f500d',
         indexes: ['packetbeat'],
         name: 'agent.id',
         searchable: true,
         type: 'string',
       },
       {
         aggregatable: true,
         category: 'agent',
         description:
           'Name of the agent. This is a name that can be given to an agent. This can be helpful if for example two Filebeat instances are running on the same host but a human readable separation is needed on which Filebeat instance data is coming from. If no name is given, the name is often left empty.',
         example: 'foo',
         indexes: ['auditbeat', 'filebeat'],
         name: 'agent.name',
         searchable: true,
         type: 'string',
       },
       {
         aggregatable: true,
         category: 'agent',
         description:
           'Type of the agent. The agent type stays always the same and should be given by the agent used. In case of Filebeat the agent would always be Filebeat also if two Filebeat instances are run on the same machine.',
         example: 'filebeat',
         indexes: ['auditbeat', 'packetbeat'],
         name: 'agent.type',
         searchable: true,
         type: 'string',
       },
       {
         aggregatable: true,
         category: 'agent',
         description: 'Version of the agent.',
         example: '6.0.0-rc2',
         indexes: ['auditbeat', 'filebeat'],
         name: 'agent.version',
         searchable: true,
         type: 'string',
       },
     ])
   );
 });
开发者ID:,项目名称:,代码行数:87,代码来源:


示例5: postprocessGroupPVJSON

              .map(function(
                groupedEntities: (PvjsonSingleFreeNode | PvjsonEdge)[]
              ): PvjsonGroup {
                const pvjsonGroup = postprocessGroupPVJSON(
                  groupedEntities,
                  pvjsonEntity
                );
                const graphIdToZIndex = processor.graphIdToZIndex;
                pvjsonGroup.contains = sortBy(
                  [
                    function(thisEntityId) {
                      return graphIdToZIndex[thisEntityId];
                    }
                  ],
                  groupedEntities.map(x => x.id)
                );

                const { id, x, y } = pvjsonGroup;

                const groupedEntitiesFinal = groupedEntities.map(function(
                  groupedEntity
                ) {
                  if (isPvjsonEdge(groupedEntity)) {
                    groupedEntity.points = map(function(point) {
                      point.x -= x;
                      point.y -= y;
                      return point;
                    }, groupedEntity.points);
                  } else if (isPvjsonSingleFreeNode(groupedEntity)) {
                    groupedEntity.height;
                    groupedEntity.x -= x;
                    groupedEntity.y -= y;
                  } else {
                    return hl.fromError(
                      new Error(
                        `
			Encountered unexpected entity
			${JSON.stringify(groupedEntity, null, "  ")}
			in Group
			${JSON.stringify(pvjsonGroup, null, "  ")}
			`
                      )
                    );
                  }
                  // NOTE: this is needed for GPML2013a, because GPML2013a uses both
                  // GroupId/GroupRef and GraphId/GraphRef. GPML2017 uses a single
                  // identifier per entity. That identifier can be referenced by
                  // GroupRef and/or GraphRef. Pvjson follows GPML2017 in this, so
                  // we convert from GPML2013a format:
                  //   GroupRef="GROUP_ID_VALUE"
                  // to pvjson format:
                  //   {isPartOf: "GRAPH_ID_VALUE"}
                  groupedEntity.isPartOf = id;
                  return omit(["groupRef"], groupedEntity);
                });

                groupedEntitiesFinal.forEach(function(pvjsonEntity) {
                  setPvjsonEntity(pvjsonEntity);
                });

                setPvjsonEntity(pvjsonGroup);

                processor.output = iassign(
                  processor.output,
                  function(o) {
                    return o.pathway.contains;
                  },
                  function(contains) {
                    return insertEntityIdAndSortByZIndex(
                      difference(contains, groupedEntitiesFinal.map(x => x["id"])),
                      id
                    );
                  }
                );

                return pvjsonGroup;
              })
开发者ID:wikipathways,项目名称:gpml2pvjson-js,代码行数:77,代码来源:toPvjson.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript fp.uniq函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fp.size函数代码示例发布时间: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