當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。