<commit_before>var protocol = require('transduce-protocol');

function load(){
  var libs = ['transducers-js', 'transducers.js'], impl;
  if(typeof process !== 'undefined' && process.env && process.env.TRANSDUCE_IMPL){
    libs = [process.env.TRANSDUCE_IMPL];
  }
  var i = 0; len = libs.length;
  for(; i < len; i++){
    try {
      impl = loader[libs[i]]();
      if(impl !== undef){
        return impl;
      }
    } catch(e){}
  }
  throw new Error('Must install one of: '+libs.join());
}

var undef, loader = {
  'transducers-js': function(){
    var impl;
    if(typeof window !== 'undefined' && window.transducers && window.transducers.Wrap){
      impl = window.transducers;
    } else {
      impl = require('transducers-js');
    }
    return impl;
  },
  'transducers.js': function(){
    //adapt methods to match transducers-js API
    var impl;
    if(typeof window !== 'undefined' && window.transducers){
      impl = window.transducers;
    } else {
      impl = require('transducers.js');
    }
    return {
      into: impl.into,
      transduce: function(xf, f, init, coll){
        f = protocol.transformer(f);
        return impl.transduce(coll, xf, f, init);
      },
      reduce: function(f, init, coll){
        f = protocol.transformer(f);
        return impl.reduce(coll, f, init);
      },
      map: nullFirst(impl, 'map'),
      filter: nullFirst(impl, 'filter'),
      remove: nullFirst(impl, 'remove'),
      take: nullFirst(impl, 'take'),
      takeWhile: nullFirst(impl, 'takeWhile'),
      drop: nullFirst(impl, 'drop'),
      dropWhile: nullFirst(impl, 'dropWhile'),
    }
    return impl;
  }
}

function nullFirst(impl, method){
  return function(f){
    return impl[method](f);
  }
}

var impl = load();

module.exports = {
  into: impl.into,
  transduce: impl.transduce,
  reduce: impl.reduce,
  map: impl.map,
  filter: impl.filter,
  remove: impl.remove,
  take: impl.take,
  takeWhile: impl.takeWhile,
  drop: impl.drop,
  dropWhile: impl.dropWhile,
  protocols: protocol.protocols,
  isIterator: protocol.isIterator,<commit_msg>Detect and load transducers.js or transducers-js from browser<commit_after>var protocol = require('transduce-protocol');

function load(){
  var libs = ['transducers-js', 'transducers.js'], impl;
  if(typeof process !== 'undefined' && process.env && process.env.TRANSDUCE_IMPL){
    libs = [process.env.TRANSDUCE_IMPL];
  }
  var i = 0; len = libs.length;
  for(; i < len; i++){
    try {
      impl = loader[libs[i]]();
      if(impl && impl.map){
        return impl;
      }
    } catch(e){}
  }
  throw new Error('Must install one of: '+libs.join());
}

var undef, loader = {
  'transducers-js': function(){
    var impl = loadFromBrowser();
    if(impl){
      if(!impl.Wrap){
        // if no Wrap exported, probably transducers.js
        impl = undef;
      }
    } else {
      impl = require('transducers-js');
    }
    return impl;
  },
  'transducers.js': function(){
    //adapt methods to match transducers-js API
    var impl = loadFromBrowser();
    if(!impl){
      impl = require('transducers.js');
    }
    return {
      into: impl.into,
      transduce: function(xf, f, init, coll){
        f = protocol.transformer(f);
        return impl.transduce(coll, xf, f, init);
      },
      reduce: function(f, init, coll){
        f = protocol.transformer(f);
        return impl.reduce(coll, f, init);
      },
      map: nullFirst(impl, 'map'),
      filter: nullFirst(impl, 'filter'),
      remove: nullFirst(impl, 'remove'),
      take: nullFirst(impl, 'take'),
      takeWhile: nullFirst(impl, 'takeWhile'),
      drop: nullFirst(impl, 'drop'),
      dropWhile: nullFirst(impl, 'dropWhile'),
    }
    return impl;
  }
}

function nullFirst(impl, method){
  return function(f){
    return impl[method](f);
  }
}

function loadFromBrowser(){
  if(typeof window !== 'undefined'){
    return window.transducers;
  }
}

var impl = load();

module.exports = {
  into: impl.into,
  transduce: impl.transduce,
  reduce: impl.reduce,
  map: impl.map,
  filter: impl.filter,
  remove: impl.remove,
  take: impl.take,
  takeWhile: impl.takeWhile,
  drop: impl.drop,
  dropWhile: impl.dropWhile,
  protocols: protocol.protocols,
  isIterator: protocol.isIterator,
{'fraction_non_alphanumeric': 0.1548964218455744, 'fraction_numerical': 0.00047080979284369113, 'mean_word_length': 2.898165137614679, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6834051', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1401, 'n_words': 336}