<commit_before>'use strict';

import 'core-js/fn/object/entries';

import createStream from 'cyclejs-stream';
import mapValues from 'map-values';
import mergeObjects from 'merge-object';
import getParametersNames from 'get-parameter-names';


function _makeInjectFn(streamWithDependencies) {
    return function inject(...inputObjects) {
        let combinedInputObject = inputObjects.length === 1 ?
            inputObjects[0] :
            inputObjects.reduce(mergeObjects, {});

        for(let [ , { dependencies, stream } ] of Object.entries(streamWithDependencies)) {
            let streamDependencies = dependencies.map((dependencyName) => {
                if(!combinedInputObject.hasOwnProperty(dependencyName)) {
                    throw new Error(`Dependency "${dependencyName}" is not available!`);
                }
                
                // shareReplay is here for circural dependent streams
                // otherwise there will be endless loop of subscribing
                return combinedInputObject[dependencyName].shareReplay(1);
            });

            stream.inject(...streamDependencies);
        }

        if (inputObjects.length === 1) {
            return inputObjects[0];
        } else if (inputObjects.length > 1) {
            return inputObjects;
        } else {
            return null;
        }
    };
}


function _makeDisposeFn(group) {
    return function dispose() {
        for (let [ , stream ] of Object.entries(group)) {
            stream.dispose();
        }
    };
}

export default function createGroup(definition) {
    let streamsDefs = ('function' === typeof definition) ?
        definition() :
        definition;

    if(('object' !== typeof streamsDefs) ||
        (streamsDefs === null) ||
        Array.isArray(streamsDefs)
    ) {
        throw new TypeError('Cycle Streams Group must be an object.');
    }

    if (this instanceof createGroup) { // jshint ignore:line
        throw new Error('Cannot use `new` operator on `createStreamsGroup()`, it is not a constructor.');
    }

    let streamsWithDeps = mapValues(streamsDefs, (streamFn) => ({
        dependencies: getParametersNames(streamFn),
        stream: createStream(streamFn)<commit_msg>remove underscores from beginning and end of function parameters names<commit_after>'use strict';

import 'core-js/fn/object/entries';

import createStream from 'cyclejs-stream';
import mapValues from 'map-values';
import mergeObjects from 'merge-object';
import getParametersNames from 'get-parameter-names';


function _removeUnderscores(string) {
    let result = /^_*(.*[^_])_*$/.exec(string);

    return result ? result[1] : string;
}


function _makeInjectFn(streamWithDependencies) {
    return function inject(...inputObjects) {
        let combinedInputObject = inputObjects.length === 1 ?
            inputObjects[0] :
            inputObjects.reduce(mergeObjects, {});

        for(let [ , { dependencies, stream } ] of Object.entries(streamWithDependencies)) {
            let streamDependencies = dependencies.map((dependencyName) => {
                if(!combinedInputObject.hasOwnProperty(dependencyName)) {
                    throw new Error(`Dependency "${dependencyName}" is not available!`);
                }
                
                // shareReplay is here for circural dependent streams
                // otherwise there will be endless loop of subscribing
                return combinedInputObject[dependencyName].shareReplay(1);
            });

            stream.inject(...streamDependencies);
        }

        if (inputObjects.length === 1) {
            return inputObjects[0];
        } else if (inputObjects.length > 1) {
            return inputObjects;
        } else {
            return null;
        }
    };
}


function _makeDisposeFn(group) {
    return function dispose() {
        for (let [ , stream ] of Object.entries(group)) {
            stream.dispose();
        }
    };
}

export default function createGroup(definition) {
    let streamsDefs = ('function' === typeof definition) ?
        definition() :
        definition;

    if(('object' !== typeof streamsDefs) ||
        (streamsDefs === null) ||
        Array.isArray(streamsDefs)
    ) {
        throw new TypeError('Cycle Streams Group must be an object.');
    }

    if (this instanceof createGroup) { // jshint ignore:line
        throw new Error('Cannot use `new` operator on `createStreamsGroup()`, it is not a constructor.');
    }

    let streamsWithDeps = mapValues(streamsDefs, (streamFn) => ({
        dependencies: getParametersNames(streamFn)
            .map(_removeUnderscores),
        stream: createStream(streamFn)
{'fraction_non_alphanumeric': 0.11023285622730186, 'fraction_numerical': 0.0027771843623157445, 'mean_word_length': 2.4401175606171934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5679940', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1183, 'n_words': 304}