本文整理汇总了TypeScript中gensequence.genSequence函数的典型用法代码示例。如果您正苦于以下问题:TypeScript genSequence函数的具体用法?TypeScript genSequence怎么用?TypeScript genSequence使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了genSequence函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: seqAffWords
seqAffWords(tapPreApplyRules?: (w: string) => any) {
const seq = genSequence(this.src.dic);
const dicWords = tapPreApplyRules ? seq.map(a => (tapPreApplyRules(a), a)) : seq;
return dicWords
.filter(a => !!a.trim())
.concatMap(dicWord => this.aff.applyRulesToDicEntry(dicWord));
}
示例2: it
it('reads words', async () => {
const reader = await pReader;
const values = genSequence(reader)
.skip(10000)
.take(10)
.toArray();
expect(values.length).to.be.equal(10);
});
示例3: dicWordsSeq
/**
* @internal
*/
dicWordsSeq(): Sequence<WordInfo> {
return genSequence(this.src.dic)
.map(line => {
const [word, rules] = line.split('/', 2);
return { word, rules, prefixes: [], suffixes: [] };
})
;
}
示例4: Promise
return new Promise((resolve, reject) => {
let resolved = false;
const out = outFile ? fs.createWriteStream(outFile) : process.stdout;
const bufferedSeq = genSequence(batch(seq, 500)).map(batch => batch.join(''));
const dataStream = iterableToStream(bufferedSeq);
const fileStream = dataStream.pipe(out);
const endEvents = ['finish', 'close', 'end'];
function resolvePromise() {
if (!resolved) {
resolved = true;
resolve();
}
}
const endHandler = () => {
cleanupStreams();
setTimeout(resolvePromise, 10);
};
const errorHandler = (e: Error) => {
cleanupStreams();
reject(e);
};
listenToStreams();
function listenToStreams() {
endEvents.forEach(event => fileStream.addListener(event, endHandler));
fileStream.addListener('error', errorHandler);
dataStream.addListener('end', endHandler);
}
function cleanupStreams() {
endEvents.forEach(event => fileStream.removeListener(event, endHandler));
fileStream.removeListener('error', errorHandler);
dataStream.removeListener('end', endHandler);
}
});
示例5: processRules
export function processRules(affInfo: AffInfo): Map<string, Rule> {
const sfxRules: Sequence<Rule> = gs(affInfo.SFX || []).map(([, sfx]) => sfx).map(sfx => ({ id: sfx.id, type: 'sfx', sfx }));
const pfxRules: Sequence<Rule> = gs(affInfo.PFX || []).map(([, pfx]) => pfx).map(pfx => ({ id: pfx.id, type: 'pfx', pfx }));
const flagRules: Sequence<Rule> = GS.sequenceFromObject(affInfo as AffTransformFlags)
.filter(([key, value]) => !!affFlag[key] && !!value)
.map(([key, value]) => ({ id: value!, type: 'flag', flags: affFlag[key]}));
const rules = sfxRules.concat(pfxRules).concat(flagRules)
.reduce<Map<string, Rule>>((acc, rule) => { acc[rule.id] = rule; return acc; }, new Map<string, Rule>());
return rules;
}