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

TypeScript lodash.flatMap函数代码示例

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

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



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

示例1: hasLabelsRelationships

const createLabelsFromTemplate = async <T extends TemplateBase>(
  template: T,
  orgID: string
): Promise<LabelMap> => {
  const {
    content: {data, included},
  } = template

  const labeledResources = [data, ...included].filter(r =>
    hasLabelsRelationships(r)
  )

  if (_.isEmpty(labeledResources)) {
    return {}
  }

  const labelRelationships = _.flatMap(labeledResources, r =>
    getLabelRelationships(r)
  )

  const includedLabels = findIncludedsFromRelationships<LabelIncluded>(
    included,
    labelRelationships
  )

  const existingLabels = await client.labels.getAll(orgID)

  const labelsToCreate = findLabelsToCreate(existingLabels, includedLabels).map(
    l => ({
      orgID,
      name: _.get(l, 'attributes.name', ''),
      properties: _.get(l, 'attributes.properties', {}),
    })
  )

  const createdLabels = await client.labels.createAll(labelsToCreate)
  const allLabels = [...createdLabels, ...existingLabels]

  const labelMap: LabelMap = {}

  includedLabels.forEach(label => {
    const createdLabel = allLabels.find(l => l.name === label.attributes.name)

    labelMap[label.id] = createdLabel.id
  })

  return labelMap
}
开发者ID:influxdata,项目名称:influxdb,代码行数:48,代码来源:index.ts


示例2: repeat

 return polyhedron.withChanges(solid => {
   return solid
     .withVertices(_.flatMap(polyhedron.vertices, v => repeat(v.value, count)))
     .mapFaces(face => {
       return _.flatMap(face.vertices, v => {
         const base = count * v.index;
         const j = mapping[face.index][v.index];
         return [base + ((j + 1) % count), base + j];
       });
     })
     .addFaces(
       _.map(polyhedron.vertices, v =>
         _.range(v.index * count, (v.index + 1) * count),
       ),
     );
 });
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:16,代码来源:truncate.ts


示例3: getAvailablePerks

/**
 * If the item has a random roll, we supply the random plug hashes it has in
 * a value named `availablePerks` to the DTR API.
 */
function getAvailablePerks(item: D2Item | DestinyVendorSaleItemComponent): number[] | undefined {
  if (isD2Item(item)) {
    if (!item.sockets) {
      return undefined;
    }

    const randomPlugOptions = _.flatMap(item.sockets.sockets, (s) =>
      s.hasRandomizedPlugItems ? s.plugOptions.map((po) => po.plugItem.hash) : []
    );

    return randomPlugOptions && randomPlugOptions.length > 0 ? randomPlugOptions : undefined;
  }

  // TODO: look up vendor rolls
  return [];
}
开发者ID:w1cked,项目名称:DIM,代码行数:20,代码来源:d2-itemTransformer.ts


示例4: constructor

  constructor(private navParams: NavParams) {
    this.client = navParams.get('client');

    var contacts = _.chain(AppStorage.get("contacts[" + this.client.id + "]")).sortBy("nom").groupBy(function(c:any) {
      return c.nom.toUpperCase()[0];
    }).value();

    var contacts_arr = [];
    _.forIn(contacts, function(value, key) {
      value.unshift({divider: key});
      contacts_arr.push(value);
    });

    this.contacts = _.flatMap(contacts_arr);

  }
开发者ID:fdelayen,项目名称:ionic-test-app,代码行数:16,代码来源:client-contacts.ts


示例5: blankVariableTemplate

export const variableToTemplate = (
  v: Variable,
  dependencies: Variable[],
  baseTemplate = blankVariableTemplate()
) => {
  const variableName = _.get(v, 'name', '')
  const templateName = `${variableName}-Template`
  const variableData = variableToIncluded(v)
  const variableRelationships = dependencies.map(d => variableToRelationship(d))
  const includedDependencies = dependencies.map(d => variableToIncluded(d))
  const includedLabels = v.labels.map(l => labelToIncluded(l))
  const labelRelationships = v.labels.map(l => labelToRelationship(l))

  const includedDependentLabels = _.flatMap(dependencies, d =>
    d.labels.map(l => labelToIncluded(l))
  )

  return {
    ...baseTemplate,
    meta: {
      ...baseTemplate.meta,
      name: templateName,
      description: `template created from variable: ${variableName}`,
    },
    content: {
      ...baseTemplate.content,
      data: {
        ...baseTemplate.content.data,
        ...variableData,
        relationships: {
          [TemplateType.Variable]: {
            data: [...variableRelationships],
          },
          [TemplateType.Label]: {
            data: [...labelRelationships],
          },
        },
      },
      included: [
        ...includedDependencies,
        ...includedLabels,
        ...includedDependentLabels,
      ],
    },
  }
}
开发者ID:influxdata,项目名称:influxdb,代码行数:46,代码来源:resourceToTemplate.ts


示例6: generatePlatforms

/**
 * @param accounts raw Bungie API accounts response
 */
async function generatePlatforms(accounts: UserMembershipData): Promise<DestinyAccount[]> {
  const accountPromises = _.flatMap(accounts.destinyMemberships, (destinyAccount) => {
    const account: DestinyAccount = {
      displayName: destinyAccount.displayName,
      platformType: destinyAccount.membershipType,
      membershipId: destinyAccount.membershipId,
      platformLabel: PLATFORM_LABELS[destinyAccount.membershipType],
      destinyVersion: 1
    };
    // PC only has D2
    return destinyAccount.membershipType === BungieMembershipType.TigerBlizzard
      ? [findD2Characters(account)]
      : [findD2Characters(account), findD1Characters(account)];
  });

  const allPromise = Promise.all(accountPromises);
  return _.compact(await allPromise);
}
开发者ID:w1cked,项目名称:DIM,代码行数:21,代码来源:destiny-account.service.ts


示例7: create

    create(sentences: string[]): {[key: string]: number} {
        let letters = _.flatMap(sentences, sentence => sentence.split(''));

        let formattedLetters = _
            .chain(letters)
            .map(s => s.toLowerCase())
            .filter(s => s.match(/[a-z]/i))
            .value();
            
        let initHistogram: {[key: string]: number} = {};
        
        let histogram = _.reduce(formattedLetters, (acc, letter) => {
                acc[letter] = (acc[letter] || 0) + 1;
                return acc;
            }, initHistogram);
            
        return histogram;
    }
开发者ID:s-soltys,项目名称:GmailStats,代码行数:18,代码来源:letterHistogramService.ts


示例8: sortTableKeys

export const latestValues = (table: Table): number[] => {
  const valueColsData = table.columnKeys
    .sort((a, b) => sortTableKeys(a, b))
    .filter(k => isValueCol(table, k))
    .map(k => table.getColumn(k)) as number[][]

  if (!valueColsData.length) {
    return []
  }

  const columnKeys = table.columnKeys
  // Fallback to `_stop` column if `_time` column missing otherwise return empty array.
  let timeColData = []
  if (columnKeys.includes('_time')) {
    timeColData = table.getColumn('_time', 'number')
  } else if (columnKeys.includes('_stop')) {
    timeColData = table.getColumn('_stop', 'number')
  }

  if (!timeColData && table.length !== 1) {
    return []
  }

  const d = (i: number) => {
    const time = timeColData[i]

    if (time && valueColsData.some(colData => !isNaN(colData[i]))) {
      return time
    }

    return -Infinity
  }

  const latestRowIndices =
    table.length === 1 ? [0] : maxesBy(range(table.length), d)

  const latestValues = flatMap(latestRowIndices, i =>
    valueColsData.map(colData => colData[i])
  )

  const definedLatestValues = latestValues.filter(x => !isNaN(x))

  return definedLatestValues
}
开发者ID:influxdata,项目名称:influxdb,代码行数:44,代码来源:latestValues.ts


示例9: getTrustlines

async function getTrustlines(
  this: RippleAPI, address: string, options: GetTrustlinesOptions = {}
): Promise<FormattedTrustline[]> {
  // 1. Validate
  validate.getTrustlines({address, options})
  const ledgerVersion = await this.getLedgerVersion()
  // 2. Make Request
  const responses = await this._requestAll('account_lines', {
    account: address,
    ledger_index: ledgerVersion,
    limit: options.limit,
    peer: options.counterparty
  })
  // 3. Return Formatted Response
  const trustlines = _.flatMap(responses, response => response.lines)
  return trustlines.map(parseAccountTrustline).filter(trustline => {
    return currencyFilter(options.currency || null, trustline)
  })
}
开发者ID:ripple,项目名称:ripple-lib,代码行数:19,代码来源:trustlines.ts


示例10: mergeWith

  return mergeWith(src, ...args, (value, srcValue, key, object, srcObject) => {
    if (!object.hasOwnProperty(key) || !srcObject.hasOwnProperty(key)) {
      return undefined
    }

    const shouldMergeToArray = validFuncs.indexOf(key) > -1
    if (shouldMergeToArray) {
      return flatMap([value, srcValue])
    }
    const [newValue, newSrcValue] = [value, srcValue].map(v => {
      if (typeof v === 'function') {
        return {
          enter: v
        }
      } else {
        return v
      }
    })
    return mergeVisitors(newValue, newSrcValue)
  })
开发者ID:YangShaoQun,项目名称:taro,代码行数:20,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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