<commit_before>const Kefir = require('./kefir');
const Observable = require('./observable');
const deprecated = require('./patterns/deprecated');
const {isFn} = require('./utils/types');
const {circleShift} = require('./utils/collections');
const {apply} = require('./utils/functions');
const {NOTHING} = require('./constants');



Kefir.Observable = Observable;
Kefir.Stream = require('./stream');
Kefir.Property = require('./property');



const {StreamStream, Emitter, neverInstance, Constant, ConstantError, Repeat} = require('./primary');

Kefir.stream = function(fn) {
  return new StreamStream(fn);
};

Kefir.Emitter = Emitter;
Kefir.emitter = deprecated('Kefir.emitter()', 'Kefir.stream()', function() {
  return new Emitter();
});

Kefir.never = function() {
  return neverInstance;
};

Kefir.constant = function(x) {
  return new Constant(x);
};

Kefir.constantError = function(x) {
  return new ConstantError(x);
};

Kefir.repeat = function(generator) {
  return new Repeat(generator);
};



const map = require('./one-source/map');

Observable.prototype.map = function(fn = (x) => x) {
  return map(this, fn);
};



const slidingWindow = require('./one-source/sliding-window');

Observable.prototype.slidingWindow = function(max, min = 0) {
  return slidingWindow(this, max, min);
};



const skipWhile = require('./one-source/skip-while');

Observable.prototype.skipWhile = function(fn = (x) => x) {
  return skipWhile(this, fn);
};



const takeWhile = require('./one-source/take-while');

Observable.prototype.takeWhile = function(fn = (x) => x) {
  return takeWhile(this, fn);
};



const skip = require('./one-source/skip');

Observable.prototype.skip = function(n) {
  return skip(this, n);
};



const take = require('./one-source/take');

Observable.prototype.take = function(n) {
  return take(this, n);
};



const skipDuplicates = require('./one-source/skip-duplicates');

Observable.prototype.skipDuplicates = function(fn = (a, b) => a === b) {
  return skipDuplicates(this, fn);
};



const skipEnd = require('./one-source/skip-end');

Observable.prototype.skipEnd = function() {
  return skipEnd(this);
};



const skipErrors = require('./one-source/skip-errors');

Observable.prototype.skipErrors = function() {
  return skipErrors(this);
};



const skipValues = require('./one-source/skip-values');

Observable.prototype.skipValues = function() {
  return skipValues(this);
};



const filterErrors = require('./one-source/filter-errors');

Observable.prototype.filterErrors = function(fn = (x) => x) {
  return filterErrors(this, fn);
};



const filter = require('./one-source/filter');

Observable.prototype.filter = function(fn = (x) => x) {
  return filter(this, fn);
};



const endOnError = require('./one-source/end-on-error');

Observable.prototype.endOnError = function() {
  return endOnError(this);
};



const diff = require('./one-source/diff');

function defaultDiff(a, b) {
  return [a, b];
}

Observable.prototype.diff = function(fn /* Function | falsey */, seed = NOTHING) {
  return diff(this, fn || defaultDiff, seed);
};



const beforeEnd = require('./one-source/before-end');

Observable.prototype.beforeEnd = function(fn) {
  return beforeEnd(this, fn);
};



const delay = require('./one-source/delay');

Observable.prototype.delay = function(wait) {
  return delay(this, wait);
};



const mapErrors = require('./one-source/map-errors');

Observable.prototype.mapErrors = function(fn = (x) => x) {
  return mapErrors(this, fn);
};



const errorsToValues = require('./one-source/errors-to-values');

Observable.prototype.errorsToValues = function(fn = (x) => ({convert: true, value: x})) {
  return errorsToValues(this, fn);
};



const valuesToErrors = require('./one-source/values-to-errors');

Observable.prototype.valuesToErrors = function(fn = (x => ({convert: true, error: x}))) {
  return valuesToErrors(this, fn);
};



const flatten = require('./one-source/flatten');

Observable.prototype.flatten = function(fn = (x) => x) {
  return flatten(this, fn);
};



const transduce = require('./one-source/transduce');

Observable.prototype.transduce = function(transducer) {
  return transduce(this, transducer);
};



const last = require('./one-source/last');

Observable.prototype.last = function() {
  return last(this);
};



const withHandler = require('./one-source/with-handler');

Observable.prototype.withHandler = function(fn) {
  return withHandler(this, fn);
};



const debounce = require('./one-source/debounce');

Observable.prototype.debounce = function(wait, {immediate = false} = {}) {
  return debounce(this, wait, {immediate});
};



const throttle = require('./one-source/throttle');

Observable.prototype.throttle = function(wait, {leading = true, trailing = true} = {}) {
  return throttle(this, wait, {leading, trailing});
};



const bufferWhile = require('./one-source/buffer-while');

Observable.prototype.bufferWhile = function(fn = (x) => x, {flushOnEnd = true} = {}) {
  return bufferWhile(this, fn, {flushOnEnd});
};



const toProperty = require('./one-source/to-property');

Observable.prototype.toProperty = function(fn = null) {
  if (fn !== null && !isFn(fn)) {
    throw new TypeError('The .toProperty method must be called with no args or with a function as an argument');
  }
  return toProperty(this, fn);
};



const changes = require('./one-source/changes');

Observable.prototype.changes = function() {
  return changes(this);
};



const scan = require('./one-source/scan');

Observable.prototype.scan = function(fn, seed = NOTHING) {
  return scan(this, fn, seed);
};



const reduce = require('./one-source/reduce');

Observable.prototype.reduce = deprecated('.reduce(fn, seed)', '.scan(fn, seed).last()',
  function(fn, seed = NOTHING) {
    return reduce(this, fn, seed);
  }
);






const {Merge, Concat, Pool, Bus, FlatMap, Zip, Combine} = require('./multiple-sources');

Kefir.merge = function(obss) {
  return new Merge(obss);
};
Observable.prototype.merge = function(other) {
  return Kefir.merge([this, other]);
};

Kefir.concat = function(obss) {
  return new Concat(obss);
};
Observable.prototype.concat = function(other) {
  return Kefir.concat([this, other]);
};

Kefir.Pool = Pool;
Kefir.pool = function() {
  return new Pool();
};

Kefir.Bus = Bus;
Kefir.bus = deprecated('Kefir.bus()', 'Kefir.pool() or Kefir.stream()', function() {
  return new Bus();
});

Observable.prototype.flatMap = function(fn) {
  return new FlatMap(this, fn)
    .setName(this, 'flatMap');
};
Observable.prototype.flatMapLatest = function(fn) {
  return new FlatMap(this, fn, {concurLim: 1, drop: 'old'})
    .setName(this, 'flatMapLatest');
};
Observable.prototype.flatMapFirst = function(fn) {
  return new FlatMap(this, fn, {concurLim: 1})
    .setName(this, 'flatMapFirst');
};
Observable.prototype.flatMapConcat = function(fn) {
  return new FlatMap(this, fn, {queueLim: -1, concurLim: 1})
    .setName(this, 'flatMapConcat');
};
Observable.prototype.flatMapConcurLimit = function(fn, limit) {
  let result;
  if (limit === 0) {
    result = Kefir.never();
  } else {
    if (limit < 0) {
      limit = -1;
    }
    result = new FlatMap(this, fn, {queueLim: -1, concurLim: limit});
  }
  return result.setName(this, 'flatMapConcurLimit');
};

Kefir.zip = function(sources, combinator) {
  return new Zip(sources, combinator);
};
Observable.prototype.zip = function(other, combinator) {
  return new Zip([this, other], combinator);
};

Kefir.combine = function(active, passive, combinator) {
  if (isFn(passive)) {
    combinator = passive;
    passive = null;
  }
  return new Combine(active, passive || [], combinator);
};
Observable.prototype.combine = function(other, combinator) {
  return Kefir.combine([this, other], combinator);
};

function id2(_, x) {return x;}
Kefir.sampledBy = deprecated(
  'Kefir.sampledBy()',
  'Kefir.combine(active, passive, combinator)',
  function(passive, active, combinator) {

    // we need to flip `passive` and `active` in combinator function
    let _combinator = combinator;
    if (passive.length > 0) {
      let passiveLength = passive.length;
      _combinator = function() {
        let args = circleShift(arguments, passiveLength);
        return combinator ? apply(combinator, null, args) : args;
      };
    }

    return new Combine(active, passive, _combinator).setName('sampledBy');
  }
);
Observable.prototype.sampledBy = function(other, combinator) {
  let _combinator;
  if (combinator) {
    _combinator = function(active, passive) {
      return combinator(passive, active);
    };
  }
  return new Combine([other], [this], _combinator || id2).setName(this, 'sampledBy');
};




require('./interval');
require('./two-sources');
require('./sugar');



Kefir.Kefir = Kefir;
module.exports = Kefir;<commit_msg>restructure entry.js<commit_after>const Kefir = require('./kefir');
const Observable = require('./observable');
const deprecated = require('./patterns/deprecated');
const {isFn} = require('./utils/types');
const {circleShift} = require('./utils/collections');
const {apply} = require('./utils/functions');
const {NOTHING} = require('./constants');
const {StreamStream, Emitter, neverInstance, Constant, ConstantError, Repeat} = require('./primary');
const {Merge, Concat, Pool, Bus, FlatMap, Zip, Combine} = require('./multiple-sources');
require('./two-sources');
require('./sugar');


Kefir.Observable = Observable;
Kefir.Stream = require('./stream');
Kefir.Property = require('./property');


// Create a stream
// -----------------------------------------------------------------------------

// - never
function never() {
  return neverInstance;
}
Kefir.never = never;

// - later
Kefir.later = require('./time-based/later');

// - interval
Kefir.interval = require('./time-based/interval');

// - sequentially
const sequentially = require('./time-based/sequentially');
Kefir.sequentially = function(wait, xs) {
  return xs.length === 0 ? never() : sequentially(wait, xs);
};

// - fromPoll
Kefir.fromPoll = require('./time-based/from-poll');

// - withInterval
Kefir.withInterval = require('./time-based/with-interval');

// - fromCallback
// - fromNodeCallback
// - fromEvents

// - stream
Kefir.stream = function(fn) {
  return new StreamStream(fn);
};


// Create a property
// -----------------------------------------------------------------------------

// - constant
Kefir.constant = function(x) {
  return new Constant(x);
};

// - constantError
Kefir.constantError = function(x) {
  return new ConstantError(x);
};

// - fromPromise


// Convert observables
// -----------------------------------------------------------------------------

// - toProperty
const toProperty = require('./one-source/to-property');
Observable.prototype.toProperty = function(fn = null) {
  if (fn !== null && !isFn(fn)) {
    throw new TypeError('The .toProperty method must be called with no args or with a function as an argument');
  }
  return toProperty(this, fn);
};

// - changes
const changes = require('./one-source/changes');
Observable.prototype.changes = function() {
  return changes(this);
};


// Modify an observable
// -----------------------------------------------------------------------------

// - map
const map = require('./one-source/map');
Observable.prototype.map = function(fn = (x) => x) {
  return map(this, fn);
};

// - filter
const filter = require('./one-source/filter');
Observable.prototype.filter = function(fn = (x) => x) {
  return filter(this, fn);
};

// - take
const take = require('./one-source/take');
Observable.prototype.take = function(n) {
  return take(this, n);
};

// - takeWhile
const takeWhile = require('./one-source/take-while');
Observable.prototype.takeWhile = function(fn = (x) => x) {
  return takeWhile(this, fn);
};

// - last
const last = require('./one-source/last');
Observable.prototype.last = function() {
  return last(this);
};

// - skip
const skip = require('./one-source/skip');
Observable.prototype.skip = function(n) {
  return skip(this, n);
};

// - skipWhile
const skipWhile = require('./one-source/skip-while');
Observable.prototype.skipWhile = function(fn = (x) => x) {
  return skipWhile(this, fn);
};

// - skipDuplicates
const skipDuplicates = require('./one-source/skip-duplicates');
Observable.prototype.skipDuplicates = function(fn = (a, b) => a === b) {
  return skipDuplicates(this, fn);
};

// - diff
const diff = require('./one-source/diff');
function defaultDiff(a, b) {
  return [a, b];
}
Observable.prototype.diff = function(fn /* Function | falsey */, seed = NOTHING) {
  return diff(this, fn || defaultDiff, seed);
};

// - scan
const scan = require('./one-source/scan');
Observable.prototype.scan = function(fn, seed = NOTHING) {
  return scan(this, fn, seed);
};

// - flatten
const flatten = require('./one-source/flatten');
Observable.prototype.flatten = function(fn = (x) => x) {
  return flatten(this, fn);
};

// - delay
const delay = require('./one-source/delay');
Observable.prototype.delay = function(wait) {
  return delay(this, wait);
};

// - throttle
const throttle = require('./one-source/throttle');
Observable.prototype.throttle = function(wait, {leading = true, trailing = true} = {}) {
  return throttle(this, wait, {leading, trailing});
};

// - debounce
const debounce = require('./one-source/debounce');
Observable.prototype.debounce = function(wait, {immediate = false} = {}) {
  return debounce(this, wait, {immediate});
};

// - valuesToErrors
const valuesToErrors = require('./one-source/values-to-errors');
Observable.prototype.valuesToErrors = function(fn = (x => ({convert: true, error: x}))) {
  return valuesToErrors(this, fn);
};

// - errorsToValues
const errorsToValues = require('./one-source/errors-to-values');
Observable.prototype.errorsToValues = function(fn = (x) => ({convert: true, value: x})) {
  return errorsToValues(this, fn);
};

// - mapErrors
const mapErrors = require('./one-source/map-errors');
Observable.prototype.mapErrors = function(fn = (x) => x) {
  return mapErrors(this, fn);
};

// - filterErrors
const filterErrors = require('./one-source/filter-errors');
Observable.prototype.filterErrors = function(fn = (x) => x) {
  return filterErrors(this, fn);
};

// - endOnError
const endOnError = require('./one-source/end-on-error');
Observable.prototype.endOnError = function() {
  return endOnError(this);
};

// - skipValues
const skipValues = require('./one-source/skip-values');
Observable.prototype.skipValues = function() {
  return skipValues(this);
};

// - skipErrors
const skipErrors = require('./one-source/skip-errors');
Observable.prototype.skipErrors = function() {
  return skipErrors(this);
};

// - skipEnd
const skipEnd = require('./one-source/skip-end');
Observable.prototype.skipEnd = function() {
  return skipEnd(this);
};

// - beforeEnd
const beforeEnd = require('./one-source/before-end');
Observable.prototype.beforeEnd = function(fn) {
  return beforeEnd(this, fn);
};

// - slidingWindow
const slidingWindow = require('./one-source/sliding-window');
Observable.prototype.slidingWindow = function(max, min = 0) {
  return slidingWindow(this, max, min);
};

// - bufferWhile
const bufferWhile = require('./one-source/buffer-while');
Observable.prototype.bufferWhile = function(fn = (x) => x, {flushOnEnd = true} = {}) {
  return bufferWhile(this, fn, {flushOnEnd});
};

// - transduce
const transduce = require('./one-source/transduce');
Observable.prototype.transduce = function(transducer) {
  return transduce(this, transducer);
};

// - withHandler
const withHandler = require('./one-source/with-handler');
Observable.prototype.withHandler = function(fn) {
  return withHandler(this, fn);
};


// Combine observables
// -----------------------------------------------------------------------------

// - combine
Kefir.combine = function(active, passive, combinator) {
  if (isFn(passive)) {
    combinator = passive;
    passive = null;
  }
  return new Combine(active, passive || [], combinator);
};
Observable.prototype.combine = function(other, combinator) {
  return Kefir.combine([this, other], combinator);
};

// - zip
Kefir.zip = function(sources, combinator) {
  return new Zip(sources, combinator);
};
Observable.prototype.zip = function(other, combinator) {
  return new Zip([this, other], combinator);
};

// - merge
Kefir.merge = function(obss) {
  return new Merge(obss);
};
Observable.prototype.merge = function(other) {
  return Kefir.merge([this, other]);
};

// - concat
Kefir.concat = function(obss) {
  return new Concat(obss);
};
Observable.prototype.concat = function(other) {
  return Kefir.concat([this, other]);
};

// - pool
Kefir.Pool = Pool;
Kefir.pool = function() {
  return new Pool();
};

// - repeat
Kefir.repeat = function(generator) {
  return new Repeat(generator);
};

// - flatMap
Observable.prototype.flatMap = function(fn) {
  return new FlatMap(this, fn)
    .setName(this, 'flatMap');
};

// - flatMapLatest
Observable.prototype.flatMapLatest = function(fn) {
  return new FlatMap(this, fn, {concurLim: 1, drop: 'old'})
    .setName(this, 'flatMapLatest');
};

// - flatMapFirst
Observable.prototype.flatMapFirst = function(fn) {
  return new FlatMap(this, fn, {concurLim: 1})
    .setName(this, 'flatMapFirst');
};

// - flatMapConcat
Observable.prototype.flatMapConcat = function(fn) {
  return new FlatMap(this, fn, {queueLim: -1, concurLim: 1})
    .setName(this, 'flatMapConcat');
};

// - flatMapConcurLimit
Observable.prototype.flatMapConcurLimit = function(fn, limit) {
  let result;
  if (limit === 0) {
    result = Kefir.never();
  } else {
    if (limit < 0) {
      limit = -1;
    }
    result = new FlatMap(this, fn, {queueLim: -1, concurLim: limit});
  }
  return result.setName(this, 'flatMapConcurLimit');
};


// Combine two observables
// -----------------------------------------------------------------------------

// - filterBy
// - sampledBy
function id2(_, x) {return x;}
Observable.prototype.sampledBy = function(other, combinator) {
  let _combinator;
  if (combinator) {
    _combinator = function(active, passive) {
      return combinator(passive, active);
    };
  }
  return new Combine([other], [this], _combinator || id2).setName(this, 'sampledBy');
};

// - takeWhileBy
// - skipWhileBy
// - skipUntilBy
// - takeUntilBy
// - bufferBy
// - bufferWhileBy
// - awaiting



// Deprecated
// -----------------------------------------------------------------------------

Kefir.Emitter = Emitter;
Kefir.emitter = deprecated('Kefir.emitter()', 'Kefir.stream()', function() {
  return new Emitter();
});

Kefir.Bus = Bus;
Kefir.bus = deprecated('Kefir.bus()', 'Kefir.pool() or Kefir.stream()', function() {
  return new Bus();
});

const reduce = require('./one-source/reduce');
Observable.prototype.reduce = deprecated('.reduce(fn, seed)', '.scan(fn, seed).last()',
  function(fn, seed = NOTHING) {
    return reduce(this, fn, seed);
  }
);

Kefir.sampledBy = deprecated('Kefir.sampledBy()', 'Kefir.combine(active, passive, combinator)',
  function(passive, active, combinator) {

    // we need to flip `passive` and `active` in combinator function
    let _combinator = combinator;
    if (passive.length > 0) {
      let passiveLength = passive.length;
      _combinator = function() {
        let args = circleShift(arguments, passiveLength);
        return combinator ? apply(combinator, null, args) : args;
      };
    }

    return new Combine(active, passive, _combinator).setName('sampledBy');
  }
);

const repeatedly = require('./time-based/repeatedly');
Kefir.repeatedly = deprecated('Kefir.repeatedly()',
  'Kefir.repeat(() => Kefir.sequentially(...)})', repeatedly);




// -----------------------------------------------------------------------------

module.exports = Kefir;
module.exports.Kefir = Kefir;
{'fraction_non_alphanumeric': 0.19947307088209962, 'fraction_numerical': 0.0012666565334143994, 'mean_word_length': 3.5552734825755827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '4644656', 'n_tokens_mistral': 6364, 'n_tokens_neox': 6135, 'n_words': 1351}