本文整理汇总了TypeScript中lodash.fromPairs函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromPairs函数的具体用法?TypeScript fromPairs怎么用?TypeScript fromPairs使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromPairs函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getAllOutcomesProfitLoss
export async function getAllOutcomesProfitLoss(db: Knex, params: GetProfitLossParamsType): Promise<AllOutcomesProfitLoss> {
const { profits, outcomeValues, buckets, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId } = await getProfitLossData(db, params);
const bucketedProfits = _.mapValues(profits, (pls, marketId) => {
return bucketAtTimestamps<ProfitLossTimeseries>(pls, buckets, Object.assign(getDefaultPLTimeseries(), { marketId }));
});
const bucketedOutcomeValues = _.mapValues(outcomeValues, (marketOutcomeValues) => {
return bucketAtTimestamps<OutcomeValueTimeseries>(marketOutcomeValues, buckets, getDefaultOVTimeseries());
});
const profit = _.mapValues(bucketedProfits, (pls, marketId) => {
return getProfitResultsForMarket(pls, bucketedOutcomeValues[marketId], buckets, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId);
});
const marketOutcomes = _.fromPairs(_.values(_.mapValues(profits, (pls) => {
const first = _.first(_.first(_.values(pls)))!;
return [first.marketId, first.numOutcomes];
})));
return {
profit,
marketOutcomes,
buckets,
};
}
示例2: map
export function makeLookup<T>(
items: Array<T>,
key: string
): { [key: string]: T } {
// Yep, we can't index into item without knowing what it is. True. But we want to.
// @ts-ignore
const pairs = map(items, item => [item[key], item]);
return fromPairs(pairs);
}
示例3: map
map(byRule, (list, ruleName) => {
const byCategory = groupBy(list, 'reasonCategory');
return [
ruleName,
fromPairs(
map(byCategory, (innerList, categoryName) => {
return [categoryName, innerList.length];
})
),
];
})
示例4: if
return _.reduce(groupedRows, (result: T | undefined, row: T): T => {
if (typeof result === "undefined") return row;
const mapped = _.map(row, (value: BigNumber | number | null, key: string): Array<any> => {
const previousValue = result[key];
if (sumFields.indexOf(key) === -1 || typeof previousValue === "undefined" || value === null || typeof value === "undefined") {
return [key, value];
} else if (BigNumber.isBigNumber(value)) {
return [key, (value as BigNumber).plus(result[key] as BigNumber)];
} else {
return [key, value + previousValue];
}
}) as Array<any>;
return _.fromPairs(mapped) as T;
}) as T;
示例5: Map
export function filterCommandLineOptions<O extends CommandMetadataOption>(options: readonly O[], parsedArgs: CommandLineOptions, predicate: OptionPredicate<O> = () => true): CommandLineOptions {
const initial: CommandLineOptions = { _: parsedArgs._ };
if (parsedArgs['--']) {
initial['--'] = parsedArgs['--'];
}
const mapped = new Map([
...options.map((o): [string, O] => [o.name, o]),
...lodash.flatten(options.map(opt => opt.aliases ? opt.aliases.map((a): [string, O] => [a, opt]) : [])),
]);
const pairs = Object.keys(parsedArgs)
.map((k): [string, O | undefined, ParsedArg | undefined] => [k, mapped.get(k), parsedArgs[k]])
.filter(([ k, opt, value ]) => opt && predicate(opt, value))
.map(([ k, opt, value ]) => [opt ? opt.name : k, value]);
return { ...initial, ...lodash.fromPairs(pairs) };
}
示例6: loadImageData
function loadImageData(state, action) {
if (action.error) {
return Object.assign({}, state, {
isLoading: false,
errorMessage: action.payload.message
})
}
let dataSet = _.fromPairs(action.payload.map(img => [img.id, img]))
return Object.assign({}, state, {
isLoading: false,
dataSet,
displayedItems: getDisplayedItems({
dataSet,
sortBy: state.sortBy,
isAscending: state.isAscending,
excludedTags: state.excludedTags
})
})
}
示例7: fromPairs
(part: [string, string, string, PredicateRaw, string]) =>
fromPairs(
zip(["axis", "namespace", "name", "predicates", "attribute"], part)
) as Record<string, any>
示例8: cb
(err, res) => {
return cb(err, _.fromPairs(res.filter(Boolean) as any[]));
}
示例9:
]).spread(function(alertEmitters, uiDescriptor) {
context.object = _.fromPairs<AlertEmitter>((_.map(alertEmitters, (alertEmitter: AlertEmitter) => [alertEmitter.name, alertEmitter]) as Array<any>));
context.userInterfaceDescriptor = uiDescriptor;
return self.updateStackWithContext(stack, context);
});