<commit_before>import { internal_queryable, internal_orderedQueryable } from './queryable';
import { generatorProto } from '../helpers';
import { set, when, compose, isSomething, constant, apply, tap, ifElse } from '../functionalHelpers';


//=========================================================================================//
//===============================          Helpers         ================================//
//=========================================================================================//
var setSource = set('source'),
    setIterator = set(Symbol.iterator),
    isIterator = apply(generatorProto.isPrototypeOf),
    queryable = ifElse(isSomething, createQueryable, createOrderedQueryable);

function constructQueryableDelegator(source, iterator, sortObj) {
    //var b = when(constant(isIterator(iterator)), set(Symbol.iterator, iterator)),
        //f = tap(isIterator, iterator); //=> true
        //f => iterator
    //TODO: I might be able to work out a composition of 'isIterator' and 'setIterator' via 'tap'. I would still
    //TODO: need the 'when' function, but if 'tap' internally runs 'isIterator', then it would return the iterator
    //TODO: object which would then be passed to the setIterator function, which would then be waiting for the
    //TODO: object argument to be passed to it.
    return compose(addGetter, when(isIterator(iterator), setIterator(iterator)), setSource)(source, queryable(sortObj));
}

function createQueryable() {
    return Object.create(internal_queryable);
}

function createOrderedQueryable(sorts) {
    return set('_appliedSorts', sorts, Object.create(internal_orderedQueryable));
}


function createNewQueryableDelegator(source, iterator) {
    var obj = Object.create(internal_queryable);
    obj.source = source;
    //if the iterator param has been passed and is a generator, objectSet it as the object's
    //iterator; other wise let the object delegate to the queryable's iterator
    if (iterator && generatorProto.isPrototypeOf(iterator))
        obj[Symbol.iterator] = iterator;

    return addGetter(obj);
}

function createNewOrderedQueryableDelegator(source, iterator, sortObj) {
    var obj = Object.create(internal_orderedQueryable);
    obj.source = source;
    //Need to maintain a list of all the sorts that have been applied; effectively,
    //the underlying sorting function will only be called a single time for
    //all sorts.
    obj._appliedSorts = sortObj;
    //if the iterator param has been passed and is a generator, objectSet it as the object's
    //iterator; other wise let the object delegate to the queryable's iterator
    if (iterator && generatorProto.isPrototypeOf(iterator))
        obj[Symbol.iterator] = iterator;

    return addGetter(obj);
}

function addGetter(obj) {
    return Object.defineProperty(
        obj,
        'data', {
            get: function _data() {
                return Array.from(this);
            }
        }
    );
}

export { createNewQueryableDelegator, createNewOrderedQueryableDelegator, constructQueryableDelegator };<commit_msg>stream: cleaned up creator functions<commit_after>import { internal_queryable, internal_orderedQueryable } from './queryable';
import { generatorProto } from '../helpers';
import { set, when, compose, isSomething, constant, apply, tap, ifElse } from '../functionalHelpers';


//=========================================================================================//
//===============================          Helpers         ================================//
//=========================================================================================//
var setSource = set('source'),
    setIterator = set(Symbol.iterator),
    isIterator = apply(generatorProto.isPrototypeOf),
    queryable = ifElse(isSomething, createQueryable, createOrderedQueryable);

function constructQueryableDelegator(source, iterator, sortObj) {
    //var b = when(constant(isIterator(iterator)), set(Symbol.iterator, iterator)),
        //f = tap(isIterator, iterator); //=> true
        //f => iterator
    //TODO: I might be able to work out a composition of 'isIterator' and 'setIterator' via 'tap'. I would still
    //TODO: need the 'when' function, but if 'tap' internally runs 'isIterator', then it would return the iterator
    //TODO: object which would then be passed to the setIterator function, which would then be waiting for the
    //TODO: object argument to be passed to it.
    return compose(when(isIterator(iterator), setIterator(iterator)), setSource)(source, queryable(sortObj));
}

function createQueryable() {
    return Object.create(internal_queryable, {
        data: {
            get: function _getData() {
                return Array.from(this);
            }
        }
    });
}

function createOrderedQueryable(sorts) {
    return set('_appliedSorts', sorts, Object.create(internal_orderedQueryable, {
        data: {
            get: function _getData() {
                return Array.from(this);
            }
        }
    }));
}

function createNewQueryableDelegator(source, iterator) {
    var obj = createQueryable();
    obj.source = source;
    //if the iterator param has been passed and is a generator, objectSet it as the object's
    //iterator; other wise let the object delegate to the queryable's iterator
    if (iterator && generatorProto.isPrototypeOf(iterator))
        obj[Symbol.iterator] = iterator;

    return obj;
}

function createNewOrderedQueryableDelegator(source, iterator, sortObj) {
    var obj = createOrderedQueryable(sortObj);
    obj.source = source;
    //Need to maintain a list of all the sorts that have been applied; effectively,
    //the underlying sorting function will only be called a single time for
    //all sorts.
    obj._appliedSorts = sortObj;
    //if the iterator param has been passed and is a generator, objectSet it as the object's
    //iterator; other wise let the object delegate to the queryable's iterator
    if (iterator && generatorProto.isPrototypeOf(iterator))
        obj[Symbol.iterator] = iterator;

    return obj;
}

export { createNewQueryableDelegator, createNewOrderedQueryableDelegator, constructQueryableDelegator };
{'fraction_non_alphanumeric': 0.16989351403678607, 'fraction_numerical': 0.0, 'mean_word_length': 3.865777080062794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2482675', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1539, 'n_words': 514}