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


TypeScript lodash.flatMap函数代码示例

本文整理汇总了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;未经允许,请勿转载。