How to use itertools - 7 common examples

To help you get started, we’ve selected a few itertools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ES-Community / nsecure / src / depWalker.js View on Github external
async function* getRootDependencies(manifest, options = Object.create(null)) {
    const { maxDepth = 4, exclude } = options;

    const { dependencies, customResolvers } = mergeDependencies(manifest, void 0);
    const parent = new Dependency(manifest.name, manifest.version);
    parent.hasCustomResolver = customResolvers.size > 0;
    parent.hasDependencies = dependencies.size > 0;

    const configRef = { exclude, maxDepth, parent };
    const iterators = [
        ...iter.filter(customResolvers.entries(), ([, valueStr]) => valueStr.startsWith("git+"))
            .map(([depName, valueStr]) => searchDeepDependencies(depName, valueStr.slice(4), configRef)),
        ...iter.map(dependencies.entries(), ([name, ver]) => searchDeepDependencies(`${name}@${ver}`, void 0, configRef))
    ];

    for await (const dep of combineAsyncIterators(...iterators)) {
        yield dep;
    }
    yield parent;

    // Add root dependencies to the exclude Map (because the parent is not handled by searchDeepDependencies)
    // if we skip this the code will fail to re-link properly dependencies in the following steps
    const depsName = await Promise.all(iter.map(dependencies.entries(), getCleanDependencyName));
    for (const [, fullRange] of depsName) {
        if (exclude.has(fullRange)) {
            exclude.get(fullRange).add(parent.fullName);
        }
    }
}
github ES-Community / nsecure / src / depWalker.js View on Github external
const configRef = { exclude, maxDepth, parent };
    const iterators = [
        ...iter.filter(customResolvers.entries(), ([, valueStr]) => valueStr.startsWith("git+"))
            .map(([depName, valueStr]) => searchDeepDependencies(depName, valueStr.slice(4), configRef)),
        ...iter.map(dependencies.entries(), ([name, ver]) => searchDeepDependencies(`${name}@${ver}`, void 0, configRef))
    ];

    for await (const dep of combineAsyncIterators(...iterators)) {
        yield dep;
    }
    yield parent;

    // Add root dependencies to the exclude Map (because the parent is not handled by searchDeepDependencies)
    // if we skip this the code will fail to re-link properly dependencies in the following steps
    const depsName = await Promise.all(iter.map(dependencies.entries(), getCleanDependencyName));
    for (const [, fullRange] of depsName) {
        if (exclude.has(fullRange)) {
            exclude.get(fullRange).add(parent.fullName);
        }
    }
}
github ES-Community / nsecure / src / depWalker.js View on Github external
async function* getRootDependencies(manifest, options = Object.create(null)) {
    const { maxDepth = 4, exclude } = options;

    const { dependencies, customResolvers } = mergeDependencies(manifest, void 0);
    const parent = new Dependency(manifest.name, manifest.version);
    parent.hasCustomResolver = customResolvers.size > 0;
    parent.hasDependencies = dependencies.size > 0;

    const configRef = { exclude, maxDepth, parent };
    const iterators = [
        ...iter.filter(customResolvers.entries(), ([, valueStr]) => valueStr.startsWith("git+"))
            .map(([depName, valueStr]) => searchDeepDependencies(depName, valueStr.slice(4), configRef)),
        ...iter.map(dependencies.entries(), ([name, ver]) => searchDeepDependencies(`${name}@${ver}`, void 0, configRef))
    ];

    for await (const dep of combineAsyncIterators(...iterators)) {
        yield dep;
    }
    yield parent;

    // Add root dependencies to the exclude Map (because the parent is not handled by searchDeepDependencies)
    // if we skip this the code will fail to re-link properly dependencies in the following steps
    const depsName = await Promise.all(iter.map(dependencies.entries(), getCleanDependencyName));
    for (const [, fullRange] of depsName) {
        if (exclude.has(fullRange)) {
            exclude.get(fullRange).add(parent.fullName);
        }
github ES-Community / nsecure / src / depWalker.js View on Github external
}

    const current = new Dependency(name, version, parent);
    if (isGit) {
        current.isGit(gitURL);
    }
    current.isDeprecated = deprecated === true;
    current.hasCustomResolver = customResolvers.size > 0;
    current.hasDependencies = dependencies.size > 0;

    if (currDepth !== maxDepth) {
        const config = {
            exclude, currDepth: currDepth + 1, parent: current, maxDepth
        };

        const gitDependencies = iter.filter(customResolvers.entries(), ([, valueStr]) => valueStr.startsWith("git+"));
        for (const [depName, valueStr] of gitDependencies) {
            yield* searchDeepDependencies(depName, valueStr.slice(4), config);
        }

        const depsNames = await Promise.all(iter.map(dependencies.entries(), getCleanDependencyName));
        for (const [fullName, cleanName] of depsNames) {
            if (exclude.has(cleanName)) {
                exclude.get(cleanName).add(current.fullName);
            }
            else {
                exclude.set(cleanName, new Set());
                yield* searchDeepDependencies(fullName, void 0, config);
            }
        }
    }
github ES-Community / nsecure / src / depWalker.js View on Github external
}
    current.isDeprecated = deprecated === true;
    current.hasCustomResolver = customResolvers.size > 0;
    current.hasDependencies = dependencies.size > 0;

    if (currDepth !== maxDepth) {
        const config = {
            exclude, currDepth: currDepth + 1, parent: current, maxDepth
        };

        const gitDependencies = iter.filter(customResolvers.entries(), ([, valueStr]) => valueStr.startsWith("git+"));
        for (const [depName, valueStr] of gitDependencies) {
            yield* searchDeepDependencies(depName, valueStr.slice(4), config);
        }

        const depsNames = await Promise.all(iter.map(dependencies.entries(), getCleanDependencyName));
        for (const [fullName, cleanName] of depsNames) {
            if (exclude.has(cleanName)) {
                exclude.get(cleanName).add(current.fullName);
            }
            else {
                exclude.set(cleanName, new Set());
                yield* searchDeepDependencies(fullName, void 0, config);
            }
        }
    }

    yield current;
}
github CSUFTitanRover / TitanRover2018 / rover / core / servers / Deepstream / mock-sensors / index.js View on Github external
sensorProps.forEach(prop => {
            let isSettingsProp = contains(['timeDelay', 'debug', 'path', 'verbose', 'deepstreamServer', 'sensorType'], prop)

            if (!isSettingsProp) {
                log(chalk.cyan(`\t- ${prop}`))
            }
        })
    });

itertools

A JavaScript port of Python's awesome itertools standard library

MIT
Latest version published 6 months ago

Package Health Score

76 / 100
Full package analysis