本文整理汇总了TypeScript中lodash.uniqWith函数的典型用法代码示例。如果您正苦于以下问题:TypeScript uniqWith函数的具体用法?TypeScript uniqWith怎么用?TypeScript uniqWith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uniqWith函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: releaseModerationCommented
public async releaseModerationCommented(requestState: RequestState, user: UserDocument, release: ReleaseDocument, message: string): Promise<SentMessageInfo[]> {
const results: SentMessageInfo[] = [];
const moderators = await state.models.User.find({ roles: { $in: ['moderator', 'root'] } }).exec();
const comments = await state.models.Comment.find({ '_ref.release_moderation': release._id }).populate('_from').exec();
const participants = comments.map(c => c._from as UserDocument);
const all: UserDocument[] = uniqWith([...moderators, ...participants, release._created_by as UserDocument], (u1: UserDocument, u2: UserDocument) => u1.id === u2.id);
const isApproved = release.moderation && release.moderation.is_approved;
for (const dest of all.filter(u => u.id !== user.id)) {
const isDestMod = moderators.includes(dest);
const isSenderMod = user.hasRole(['moderator', 'root']);
const isDestParticipant = participants.includes(dest);
const game = release._game as GameDocument;
const subject = isDestMod ?
'New comment on "' + release.name + '" of ' + game.title :
'Comment about your submitted "' + release.name + '" of ' + game.title;
const result = await this.sendEmail(requestState, dest, subject, 'release-moderation-commented', {
user: dest,
who: isSenderMod ? 'Moderator' : 'Uploader',
what: isSenderMod ? (isDestMod ? (release._created_by as UserDocument).name + '\'s' : 'your') : 'his',
release,
game,
commentor: user,
message: this.wrapMessage(message),
url: settings.webUri('/games/' + game.id + '/releases/' + release.id + (isApproved ? '?show-moderation' : '')),
}, isDestParticipant || !isDestMod ? null : 'moderator_notify_release_commented');
results.push(result);
}
return results;
}
开发者ID:freezy,项目名称:node-vpdb,代码行数:32,代码来源:mailer.ts
示例2: resolve
let finalize = () => {
//let count = this.transactionList.length
this.transactionList = _.uniqWith(this.transactionList, _.isEqual);
//console.log(`Number of duplicates: ${ count - this.transactionList.length}`)
this.isReady = true;
resolve(this.transactionList);
};
开发者ID:aheinrich,项目名称:bench-resttest,代码行数:9,代码来源:transactions.service.ts
示例3: split
split(t1: number, t2: number): Calculator {
if (t1 === t2) {
return new PointCalculator(this.id, this.svgChar, this.bezierJs.get(t1) as Point);
}
const points: ReadonlyArray<Point> = this.bezierJs.split(t1, t2).points;
const uniquePoints: Point[] = _.uniqWith(points, MathUtil.arePointsEqual);
if (uniquePoints.length === 2) {
return new LineCalculator(this.id, this.svgChar, _.first(points), _.last(points));
}
return new BezierCalculator(this.id, this.svgChar, ...points);
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:11,代码来源:BezierCalculator.ts
示例4: xorWith
const combineFilterValues: TCombineValues = (x, y, type) => {
const xValue = ([] as TFilterValue).concat(x.content.value || []);
const yValue = ([] as TFilterValue).concat(y.content.value || []);
return {
op: 'in',
content: {
field: x.content.field,
value: (type === 'toggle'
? xorWith(xValue, yValue, isEqual)
: uniqWith([...xValue, ...yValue], isEqual)
).sort(),
},
};
};
开发者ID:NCI-GDC,项目名称:portal-ui,代码行数:15,代码来源:index.ts
示例5: uniqWith
.then((searchResults: ISearchResults<IHealthCheckSearchResults>) => {
if (searchResults && searchResults.results) {
const healthChecks = searchResults.results.filter(result => result.provider === 'gce')
.map(result => {
const healthCheck = JSON.parse(result.healthCheck) as IGceHealthCheck;
healthCheck.account = result.account;
return healthCheck;
});
return uniqWith(healthChecks, (checkA: IGceHealthCheck, checkB: IGceHealthCheck) => {
return checkA.name === checkB.name && checkA.healthCheckType === checkB.healthCheckType &&
checkA.account === checkB.account;
});
} else {
return [];
}
})
开发者ID:robfletcher,项目名称:deck,代码行数:16,代码来源:healthCheck.read.service.ts
示例6: convertToCustomAlerts
convertToCustomAlerts(
alerts: (PrometheusNotificationAlert | PrometheusAlert)[]
): PrometheusCustomAlert[] {
return _.uniqWith(
alerts.map((alert) => {
return {
status: _.isObject(alert.status)
? (alert as PrometheusAlert).status.state
: this.getPrometheusNotificationStatus(alert as PrometheusNotificationAlert),
name: alert.labels.alertname,
url: alert.generatorURL,
summary: alert.annotations.summary,
fingerprint: _.isObject(alert.status) && (alert as PrometheusAlert).fingerprint
};
}),
_.isEqual
) as PrometheusCustomAlert[];
}
开发者ID:ceph,项目名称:ceph,代码行数:18,代码来源:prometheus-alert-formatter.ts
示例7: newCalculator
export function newCalculator(cmd: Command): Calculator {
const points = cmd.points;
if (cmd.type === 'M') {
return new MoveCalculator(cmd.id, points[0], points[1]);
}
const uniquePoints: Point[] = _.uniqWith(points, MathUtil.arePointsEqual);
if (uniquePoints.length === 1) {
return new PointCalculator(cmd.id, cmd.type, points[0]);
}
if (cmd.type === 'L' || cmd.type === 'Z' || uniquePoints.length === 2) {
return new LineCalculator(cmd.id, cmd.type, _.first(points), _.last(points));
}
if (cmd.type === 'Q') {
return new BezierCalculator(cmd.id, cmd.type, points[0], points[1], points[2]);
}
if (cmd.type === 'C') {
const pts = cmd.points;
return new BezierCalculator(cmd.id, cmd.type, pts[0], pts[1], pts[2], pts[3]);
}
throw new Error('Invalid command type: ' + cmd.type);
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:21,代码来源:Calculator.ts
示例8: uniqWith
function concat<T>(arrA?: T[], arrB?: T[]): T[] {
return uniqWith((arrA || []).concat(arrB || []), isEqual)
}
开发者ID:patrickhulce,项目名称:klay,代码行数:3,代码来源:options.ts
示例9: mergeInterfaces
function mergeInterfaces(interfaces: Interface[]): void {
const mainInterface = interfaces[0];
if (!mainInterface)
return;
mainInterface.overloads = _.uniqWith(_.flatMap(interfaces, i => i.overloads), _.isEqual);
}
开发者ID:Q-Man,项目名称:DefinitelyTyped,代码行数:6,代码来源:generate-fp.ts
示例10: curryDefinition
function curryDefinition(definition: Definition, paramOrder: number[], spreadIndex: number, isFixed: boolean): Interface[] {
// Remove any duplicate/redundant overloads
let overloads = _.uniqWith(_.cloneDeep(definition.overloads),
(a, b) => _.isEqual(a.params, b.params) && _.isEqual(getUsedTypeParams(a.params, a.typeParams), getUsedTypeParams(b.params, b.typeParams)));
const functionName = definition.name;
// Remove unused type parameters
for (const overload of overloads) {
for (let i = 0; i < overload.typeParams.length; ++i) {
const typeParam = overload.typeParams[i];
const search = new RegExp(`\\b${typeParam.name}\\b`);
if (overload.params.every(p => !search.test(p)) && !search.test(overload.returnType)) {
// overload.returnType = overload.returnType.replace(search, typeParam.extends || "any");
overload.typeParams.splice(i, 1);
--i;
}
}
}
if (!isFixed) {
// Non-fixed arity functions cannot be curried.
for (const overload of overloads)
overload.params = overload.params.map(p => p.replace(/\?:/g, ":")); // No optional parameters
return [{
name: getInterfaceBaseName(functionName),
typeParams: [],
overloads,
constants: definition.constants,
}];
}
paramOrder = paramOrder.filter(p => typeof p === "number");
const arity = paramOrder.length;
if (spreadIndex !== -1) {
// The parameter at this index is an array that will be spread when passed down to the actual function (e.g. assignAll, invokeArgs, partial, without).
// For these parameters, we expect the input to be an array (so remove the "...")
// Spread/rest parameters could be in any of the following formats:
// 1. The rest parameter is at spreadIndex, and it is the last parameter.
// 2. The rest parameter is immediately after spreadIndex, e.g. assign(object, ...sources[]). In this case, convert it to assignAll(...object[])
// 3. The rest parameter is not the last parameter, e.g. assignWith(object, ...sources[], customizer)
if (spreadIndex === arity - 1) {
// cases 1-2
for (let i = 0; i < overloads.length; ++i) {
const overload = overloads[i];
if (overload.params.length === arity && overload.params[spreadIndex] && overload.params[spreadIndex].startsWith("...")) {
overload.params[spreadIndex] = overload.params[spreadIndex].replace("...", "");
} else if (overload.params.length === arity + 1 && overload.params[spreadIndex + 1] && overload.params[spreadIndex + 1].startsWith("...")) {
overload.params.splice(spreadIndex + 1, 1);
const parts = overload.params[spreadIndex].split(":").map(_.trim);
parts[1] = `ReadonlyArray<${parts[1]}>`;
overload.params[spreadIndex] = `${parts[0]}: ${parts[1]}`;
} else {
_.pull(overloads, overload);
--i;
}
}
} else {
// case 3
const overload = overloads[0];
overloads = [{
jsdoc: overload.jsdoc,
typeParams: [],
params: [
...overload.params.slice(0, spreadIndex),
"args: ReadonlyArray<any>",
...overload.params.slice(overload.params.length - (arity - spreadIndex - 1)),
],
returnType: "any",
}];
}
}
let filteredOverloads = overloads.filter(o => o.params.length >= arity && o.params.slice(arity).every(p => p.includes("?") && !p.startsWith("iteratee"))
&& o.params.every(p => !p.startsWith("...") && !p.startsWith("guard:")));
if (filteredOverloads.length === 0)
filteredOverloads = overloads.filter(o => o.params.length >= arity && o.params.slice(arity).every(p => p.includes("?") || p.startsWith("..."))
&& o.params.every(p => !p.startsWith("guard:")));
if (filteredOverloads.length === 0)
filteredOverloads = overloads.filter(o => o.params.length > 0 && o.params.length <= arity + 1 && o.params[o.params.length - 1].startsWith("..."));
if (filteredOverloads.length === 0)
console.warn(`No matching overloads found for ${functionName} with arity ${arity}`);
const restOverloads = overloads.filter(o => o.params.length > 0 && o.params[o.params.length - 1].startsWith("..."));
for (const restOverload of restOverloads) {
restOverload.params[restOverload.params.length - 1] = restOverload.params[restOverload.params.length - 1]
.substring(3)
.replace(/\[\]$/, "")
.replace(/: Array<(.+)>$/, ": $1");
if (restOverload.params.length < arity) {
const paramToCopy = restOverload.params[restOverload.params.length - 1];
const copiedParams = _.range(2, arity - restOverload.params.length + 2).map(i => paramToCopy.replace(/(^.+?):/, `$1${i}:`));
restOverload.params.push(...copiedParams);
}
}
for (const overload of filteredOverloads)
preProcessOverload(overload, functionName, arity);
const interfaces = _.flatMap(filteredOverloads, (o, i) => {
const reargParams = o.params.map((p, i) => o.params[paramOrder.indexOf(i)]);
//.........这里部分代码省略.........
开发者ID:MichaelBuen,项目名称:DefinitelyTyped,代码行数:101,代码来源:generate-fp.ts
注:本文中的lodash.uniqWith函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论