本文整理汇总了TypeScript中lodash.takeWhile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript takeWhile函数的具体用法?TypeScript takeWhile怎么用?TypeScript takeWhile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了takeWhile函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: categorizedTokens
@memoizeAccessor
private get categorizedTokens() {
/**
* @link http://stackoverflow.com/a/10939280/1149074
*/
const parameterAssignmentTokens = _.takeWhile(this.tokens, token => token.value.includes("="));
const commandWordToken = this.tokens[parameterAssignmentTokens.length];
const beforeArgumentListTokensCount = parameterAssignmentTokens.length + 1;
const argumentListTokens = _.takeWhile(this.tokens.slice(beforeArgumentListTokensCount), token => !(
token instanceof Scanner.InputRedirectionSymbol ||
token instanceof Scanner.OutputRedirectionSymbol ||
token instanceof Scanner.AppendingOutputRedirectionSymbol
));
const ioRedirectTokens = this.tokens.slice(beforeArgumentListTokensCount + argumentListTokens.length);
return {
parameterAssignment: parameterAssignmentTokens,
commandWord: commandWordToken,
argumentList: argumentListTokens,
ioRedirect: ioRedirectTokens,
};
}
示例2:
return _.map(timestampeds, (values, outcome: string) => {
let result: T | undefined;
const beforeBucket = _.takeWhile(values, (pl) => pl.timestamp <= bucket.timestamp);
if (beforeBucket.length > 0) {
_.drop(values, beforeBucket.length);
result = _.last(beforeBucket);
}
if (!result) result = Object.assign({ outcome }, defaultValue);
result.timestamp = bucket.timestamp;
return result;
});
示例3: getCommonAncestor
// given two paths, returns
// 1. the common ancestor of the paths
// 2. the array of ancestors between common ancestor and path1
// 3. the array of ancestors between common ancestor and path2
public async getCommonAncestor(path1: Path, path2: Path): Promise<[Path, Array<Path>, Array<Path>]> {
const ancestors1: Array<Path> = path1.getAncestryPaths();
const ancestors2: Array<Path> = path2.getAncestryPaths();
const commonAncestry = _.takeWhile(
_.zip(ancestors1, ancestors2),
(pair: any) => (pair[0] && pair[1] && pair[0].is(pair[1]))
).map((pair) => pair[0]);
const lastCommon = _.last(commonAncestry);
if (lastCommon == null) {
throw new Error(`No common ancestor found between ${path1} and ${path2}`);
}
const firstDifference = commonAncestry.length;
return [lastCommon, ancestors1.slice(firstDifference), ancestors2.slice(firstDifference)];
}