<commit_before>var accessor = require('./lib/accessor');
var arrow = require('./lib/arrow');
var mapper = require('./lib/mapper');
var functor = require('./lib/functor');
var dotmap = require('dotmap');

var fof = function(x) {
  switch (typeof x) {

    case 'function':
      return x;

    case 'number':
      return accessor(x);

    case 'object':
      // because `typeof null === 'object'`, obviously
      if (x === null) {
        return functor(x);
      } else {
        return mapper(x, fof.bind(this));
      }

    case 'boolean':
    case 'undefined':
      return functor(x);
  }

  var fat = arrow(x);
  if (fat) {
    return fat;
  }

  // dotmap handles booleans with a functor
  return dotmap(x);
};

module.exports = fof;<commit_msg>add fof.stream()<commit_after>var accessor = require('./lib/accessor');
var arrow = require('./lib/arrow');
var mapper = require('./lib/mapper');
var functor = require('./lib/functor');
var dotmap = require('dotmap');
var through2 = require('through2');

var fof = function(x) {
  switch (typeof x) {

    case 'function':
      return x;

    case 'number':
      return accessor(x);

    case 'object':
      // because `typeof null === 'object'`, obviously
      if (x === null) {
        return functor(x);
      } else {
        return mapper(x, fof.bind(this));
      }

    case 'boolean':
    case 'undefined':
      return functor(x);
  }

  var fat = arrow(x);
  if (fat) {
    return fat;
  }

  // dotmap handles booleans with a functor
  return dotmap(x);
};

fof.stream = function(x, options) {
  var filter = (options && typeof options === 'object')
    ? options.filter
    : false;

  var transform = fof(x);
  if (typeof filter !== 'boolean') {
    filter = fof(filter);
  }

  var thru = (typeof filter === 'function')
    ? function(d, enc, next) {
        var filtered = filter(d);
        return filtered
          ? next()
          : next(null, f(d));
      }
    : function(d, enc, next) {
        var out = f(d);
        return out === false
          ? next()
          : next(null, filter ? d : out);
      };
  return through2.obj(thru);
};

module.exports = fof;
{'fraction_non_alphanumeric': 0.1639496972519795, 'fraction_numerical': 0.0013972985561248254, 'mean_word_length': 2.3933649289099526, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1604439', 'n_tokens_mistral': 712, 'n_tokens_neox': 685, 'n_words': 191}