本文整理汇总了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
}
示例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),
),
);
});
示例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 [];
}
示例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);
}
示例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,
],
},
}
}
示例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);
}
示例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;
}
示例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
}
示例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)
})
}
示例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)
})