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


TypeScript ramda.groupBy函数代码示例

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


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

示例1:

export const unnest = (categories: Category[]): Category[] => {
  const children = R.groupBy(R.pathOr('root', ['parent', 'name']), categories);

  return children.root.map(category => ({
    ...category,
    children: children[category.name] || []
  }))
}
开发者ID:apuchenkin,项目名称:aws.photo.service,代码行数:8,代码来源:category.ts

示例2: async

export default async () => {
  const pages = await fetch(`${host}${basename}/page`, options).then(res => res.json());

  const pages$ = await Promise.all(
    pages.map((page: any) => fetch(
      `${host}${basename}/page/${page.alias}`,
      options,
    )
    .then(res => res.json())
    )
  );

  const categories = await fetch(`${host}${basename}/category`, options).then(res => res.json());

  const categories$ = await Promise.all(
    categories.map((category: any) => fetch(
      `${host}${basename}/category/${category.name}`,
      options,
    )
    .then(res => res.json())
    .catch(e=> {
      console.log(e);
    })
    )
  );

  const photos = await Promise.all(
    categories.map((category: any) => fetch(
      `${host}${basename}/category/${category.name}/photo`,
      options,
    )
    .then(res => res.json())
    .catch(() => [])
    .then(photos => photos.map((photo: any) => ({
      ...photo,
      category: category.name,
    })))
    )
  );

  const photos$ = R.pipe(
    R.unnest,
    R.groupBy(R.prop('id')),
    // @ts-ignore
    R.map((photoList: Photo[]) => ({
      ...R.head(photoList),
      category: R.map(R.prop('category'), photoList)
    })),
    R.values,
  )(photos);

  return {
    pages: pages$.filter(Boolean),
    categories: categories$.filter(Boolean),
    photos: photos$.filter(Boolean),
  } as any;
};
开发者ID:apuchenkin,项目名称:aws.photo.service,代码行数:57,代码来源:fetchData.ts

示例3: listMigrations

export function listMigrations(directory: string): Promise<Migration[]> {
  return fs.readdirAsync(directory)
    .map(R.match(MIGRATION_FILE_REGEXP))
    .filter(R.identity)
    .then(R.groupBy(R.nth<string>(1)))
    .then(R.mapObj(R.partial(matchesToMigration, directory)))
    .then(R.values)
    .then(R.sortBy((migration: Migration) => migration.id));
}
开发者ID:programble,项目名称:careen,代码行数:9,代码来源:files.ts

示例4: sort

    public static sort(unsorted: number [] = []): number[] {

        if (unsorted.length !== 0) {
            const sorted = [];
            const m = R.head(unsorted);

            const {l, h} = R.groupBy(curr => R.gte(curr, m) ? 'h' : 'l', R.drop(1, unsorted))

            sorted.push(...QuickSort.sort(l));
            sorted.push(m);
            sorted.push(...QuickSort.sort(h));
            return sorted;
        } else
            return unsorted;
    }
开发者ID:sprengerjo,项目名称:katas_js,代码行数:15,代码来源:quick_sort.ts

示例5: parseCandidateAnswers

function parseCandidateAnswers(fileContent: string): Candidate[] {
  const rows: string[][] = parse(fileContent);
  const rowsByCandidate = R.groupBy(row => row[AnswerFileCols.NAME], rows.slice(1));
  const candidateRowPairs: [string, Row[]][] = R.toPairs(rowsByCandidate) as any;
  return candidateRowPairs.map((candidateAndAnswerRows: [string, Row[]]) => {
    const candidateName = candidateAndAnswerRows[0];
    const answerRows = candidateAndAnswerRows[1];
    const oneRow = answerRows[0];
    return {
      answers: getAnswerMapFromRows(answerRows),
      id: candidateName,
      name: candidateName,
      party: oneRow[AnswerFileCols.PARTY],
      reasons: getReasonsMapFromRows(answerRows),
      regions: oneRow[AnswerFileCols.REGION].split(/,\s+/)
    };
  });
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:18,代码来源:convert.ts

示例6: groupBy

const groupByLength = (
  w: string[],
): {
  [key: number]: string[];
} => groupBy(length as any, w as any) as any;
开发者ID:kerlends,项目名称:word-solver,代码行数:5,代码来源:solver.worker.ts

示例7: isByLinode

const isDeprecated = (i: Linode.Image) => i.deprecated === true;
const isRecommended = (i: Linode.Image) => isByLinode(i) && !isDeprecated(i);
const isOlderImage = (i: Linode.Image) => isByLinode(i) && isDeprecated(i);

interface GroupedImages {
  deleted?: Linode.Image[];
  recommended?: Linode.Image[];
  older?: Linode.Image[];
  images?: Linode.Image[];
}

export let groupImages: (i: Linode.Image[]) => GroupedImages;
groupImages = groupBy(
  cond([
    [isRecentlyDeleted, always('deleted')],
    [isRecommended, always('recommended')],
    [isOlderImage, always('older')],
    [(i: Linode.Image) => true, always('images')]
  ])
);

export const groupNameMap = {
  _default: 'Other',
  deleted: 'Recently Deleted Disks',
  recommended: '64-bit Distributions - Recommended',
  older: 'Older Distributions',
  images: 'Images'
};

export const getDisplayNameForGroup = (key: string) =>
  propOr('Other', key, groupNameMap);
开发者ID:linode,项目名称:manager,代码行数:31,代码来源:images.ts


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