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


TypeScript ramda.map函數代碼示例

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


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

示例1: createCorrectReplacementSet

  private createCorrectReplacementSet(syllable: string) {
    const vowels = ['a', 'e', 'i', 'o', 'u'];
    const knownVowels = intersection(vowels, this.letters);
    const longVowels = map(vowel => vowel + vowel, vowels);
    const knownLongVowels = map(vowel => vowel + vowel, knownVowels);
    const diphtongs = ['ie', 'ei', 'au', 'eu', 'äu'];
    const umlauts = ['ä', 'ö', 'ü'];

    // start with the sets containing strings of length two!
    const possibleReplacementSetsLowercase = [
      knownLongVowels,
      diphtongs,
      longVowels,
      umlauts,
      knownVowels,
      vowels
    ];
    const possibleReplacementSetsCapitalized = map(
      set => map(capitalizeFirstLetter, set),
      possibleReplacementSetsLowercase
    );
    return find(
      set => set.length > 0 && new RegExp(join('|', set), 'g').test(syllable),
      [
        ...possibleReplacementSetsCapitalized,
        ...possibleReplacementSetsLowercase
      ]
    );
  }
開發者ID:serlo-org,項目名稱:serlo-abc,代碼行數:29,代碼來源:connect-syllables.ts

示例2: extractDefinition

const composeSenseData = (senseMarkup: string): SenseData => {
    const definition = extractDefinition(senseMarkup)
    const situation = extractSituation(senseMarkup)
    const geography = extractGeography(senseMarkup)
    const synonym = extractSynonym(senseMarkup)
    const antonym = extractAntonym(senseMarkup)
    const examples = extractExamples(senseMarkup)
    const exampleGroups = R.pipe(
        splitBySelector({
            selector: '.ColloExa, .GramExa',
            onlyChildren: true
        }),
        R.map(composeExampleGroupData)
    )(senseMarkup)
    const subsenses = R.pipe(
        splitBySelector({ selector: '.Subsense' }),
        R.map(composeSenseData)
    )(senseMarkup)

    const senseData = {
        definition,
        situation,
        geography,
        synonym,
        antonym,
        examples,
        exampleGroups,
        subsenses
    }

    return senseData
}
開發者ID:yakhinvadim,項目名稱:longman-to-anki,代碼行數:32,代碼來源:composeSenseData.ts

示例3: 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

示例4: generateExercises

  protected generateExercises() {
    const letterSymbols: Figure[] = this.newLetter
      ? [
          { name: this.newLetter.toLowerCase(), isIcon: false },
          ...(this.newLetter === 'ß'
            ? []
            : [{ name: capitalizeFirstLetter(this.newLetter), isIcon: false }])
        ]
      : [];
    const allTextSymbols: Figure[] = map(
      symbol => ({ name: symbol, isIcon: false }),
      // prettier-ignore
      [
        '0','1','2','3', '4', '5', '6', '7', '8', '9',
        '=', '!', '"', '§', '$', '%', '&', '/', '(', ')',
        '?', '<', '>', ',', ';', '.', ':', '*', '+', '#', "'", '.', '_', '-'
      ]
    );
    const allIconSymbols: Figure[] = map(
      icon => ({ name: icon, isIcon: true }),
      // prettier-ignore
      [
        'autorenew', 'block', 'bluetooth', 'border-all', 'camera', 'crop-free',
        'directions-subway', 'done', 'event-seat', 'extension', 'favorite-border',
        'fingerprint', 'flight', 'headset', 'healing', 'highlight', 'lightbulb-outline',
        'local-bar', 'local-phone', 'mic', 'nature', 'notifications', 'remove-red-eye',
        'security', 'star-border', 'usb', 'watch', 'whatshot'
      ]
    );
    const version = sample(['a', 'b'], 1);

    return [
      this.createExercise(ExerciseTypes.InfoScreenWithSounds, {
        type: 'ExplanationText',
        text: `Finden Sie den Buchstaben`,
        sound: `exercises_finden_sie_den_buchstaben_${version}`
      }),
      this.createExercise(ExerciseTypes.InfoScreen, {
        type: 'TutorialVideo',
        video: 'explanation_differ_from_symbol'
      }),
      ...map(letter => {
        const selectedSymbols: Figure[] = sample(
          concat(allTextSymbols, allIconSymbols),
          4
        );
        const symbols = sample(
          [...selectedSymbols, letter],
          selectedSymbols.length + 1
        );
        return this.createExercise(ExerciseTypes.DifferFromSymbol, {
          type: 'DifferFromSymbol',
          symbols,
          correctIndex: symbols.indexOf(letter)
        });
      }, letterSymbols)
    ];
  }
開發者ID:serlo-org,項目名稱:serlo-abc,代碼行數:58,代碼來源:differ-from-symbol.ts

示例5: async

 async (data: IOMessage[]) => {
   const to = data[0].to // Should be consistent across batches
   const indexedData = toPairs(data) as Array<[string, IOMessage]>
   const sortedIndexedData = sortByContent(indexedData)
   const originalIndexes = pluck(0, sortedIndexedData) as string[]
   const sortedData = pluck(1, sortedIndexedData) as IOMessage[]
   const strLength = map(obj => JSON.stringify(obj).length, sortedData)
   const batches = batchData(strLength, sortedData)
   const promises = map((batch: IOMessage[]) => !!to ? messagesAPI.translate(to, batch) : Promise.resolve(pluck('content', batch)), batches)
   const translations = await Promise.all(promises).then(res => flatten<string>(res))
   const indexedTranslations = zip(originalIndexes, translations) as Array<[string, string]>
   const translationsInOriginalOrder = sortByOriginalIndex(indexedTranslations)
   return pluck(1, translationsInOriginalOrder)
 }
開發者ID:vtex,項目名稱:apps-client-node,代碼行數:14,代碼來源:messagesLoader.ts

示例6: Promise

        R.map(file => {
          const source = path.join(imagesPath, file);

          // Create three output files
          const targets = R.map(
            suffix =>
              path.join(
                outputPath,
                `${getFilename(file)}${suffix}${getExtname(file)}`
              ),
            suffixes
          );

          return Promise.all(
            R.zipWith(
              (target, size) =>
                new Promise((resolve, reject) => {
                  gm(source)
                    .resize(size, size, '!')
                    .quality(0.8)
                    .write(target, err => {
                      if (err) {
                        reject(err);
                        return;
                      }

                      resolve();
                    });
                }),
              targets,
              sizes
            )
          );
        }, files)
開發者ID:serlo-org,項目名稱:serlo-abc,代碼行數:34,代碼來源:generate-words-images.ts

示例7: 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

示例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: initializeNavigation

  private initializeNavigation(models: NavModel[]): void {
    const mapName: any = R.map((model: NavModel) => {
      return [model.config.route, model];
    });

    this.navigation = R.pipe(mapName, R.fromPairs)(models) as { [k: string]: NavModel };
  }
開發者ID:devkat,項目名稱:calendar,代碼行數:7,代碼來源:navigation.ts


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