當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ramda.fromPairs函數代碼示例

本文整理匯總了TypeScript中ramda.fromPairs函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fromPairs函數的具體用法?TypeScript fromPairs怎麽用?TypeScript fromPairs使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了fromPairs函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getReasonsMapFromRows

function getReasonsMapFromRows(answerRows: Row[]): ReasonMap {
  const pairs = answerRows.map((answerRow: string[]) =>
    [answerRow[AnswerFileCols.QUESTION_NUMBER], answerRow[AnswerFileCols.REASON]] as [string, string]
  );
  return R.fromPairs(pairs);
}
開發者ID:shybyte,項目名稱:wahlomat,代碼行數:6,代碼來源:convert.ts

示例2: getAnswerMapFromRows

function getAnswerMapFromRows(answerRows: string[][]): AnswerMap {
  const pairs = answerRows.map((answerRow: string[]) =>
    [answerRow[AnswerFileCols.QUESTION_NUMBER], toAnswer(answerRow[AnswerFileCols.ANSWER])] as [string, Answer]
  );
  return R.fromPairs(pairs);
}
開發者ID:shybyte,項目名稱:wahlomat,代碼行數:6,代碼來源:convert.ts

示例3: castModelName

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

  const enumFilterFields = R.filter(R.propEq('type', DynamicFormTypes.EnumFilter))(fields);
  if (R.not(R.isEmpty(enumFilterFields))) {
    const [, enumFilterField] = R.toPairs(enumFilterFields)[0];
    logger.debug(TAG, { enumFilterField });

    const enums = _.map(
      _.keys(idx(enumFilterField as EnumField, _ => _.options.enumData)),
      castModelName,
    );
    const current = castModelName(R.pathOr('', ['value'])(enumFilterField));
    logger.debug(TAG, { enums, current });

    // check if positions has value already
    // save positions value if no value exists, update models' sequence for else
    const positionsFieldPair = R.compose(
      R.toPairs,
      R.map(field => {
        // raw is the original value, if exists, means it's update request
        if (field.value && !field.raw) {
          const value = R.is(String, field.value) ? JSON.parse(field.value) : field.value;
          return { ...field, value, raw: field.value };
        }
        return { ...field, value: R.path([current, 'value'])(fields), raw: field.value };
      }),
      R.filter(R.pathEq(['options', 'type'], 'SortPosition')),
    )(fields);

    const filteredNames = R.without(current)(enums);
    const filteredFields = R.omit(filteredNames)(fields);
    const wrappedFields = current
      ? R.mergeDeepRight(filteredFields, {
          [current]: {
            isFilterField: true,
            options: { filterType: R.path(['options', 'filterType'])(enumFilterField) },
            value: R.isEmpty(positionsFieldPair)
              ? R.path([current, 'value'])(filteredFields)
              : R.path([0, 1, 'value'])(positionsFieldPair),
          },
          ...R.fromPairs(positionsFieldPair),
        })
      : filteredFields;

    logger.debug(TAG, 'wrappedFields', {
      current,
      filteredNames,
      filteredFields,
      wrappedFields,
      positionsFieldPair,
    });

    return { modelName, fields: wrappedFields };
  }

  return { modelName, fields };
};
開發者ID:danielwii,項目名稱:asuna-admin,代碼行數:65,代碼來源:index.ts

示例4:

/**
 * This file ties together the library's EntityGenerator class with the game's entity templates.
 * It must be imported once to complete this process.
 * After it has been imported once, the generator can be referenced by importing either this file
 * or the original file.
 */
'use strict';
import templates from './data/entities/index';
import EntityGenerator from 'shattered-lib/generators/EntityGenerator';
import R from 'ramda';

let _templates = R.fromPairs(R.map(template=>[template.name, template], R.flatten(R.values(templates))));
EntityGenerator._templates = _templates;

export default EntityGenerator;
開發者ID:nathantreid,項目名稱:shattered-planes,代碼行數:15,代碼來源:EntityGenerator.ts

示例5: getSimilarities

export function getSimilarities(answerMap: AnswerMap, weights: WeightMap, candidates: Candidate[]): NumberMap {
  const pairs = candidates.map(candidate => [candidate.id, getSimilarity(answerMap, weights, candidate)] as [string, number]);
  return R.fromPairs(pairs);
}
開發者ID:shybyte,項目名稱:wahlomat,代碼行數:4,代碼來源:model.ts


注:本文中的ramda.fromPairs函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。