<commit_before>'use strict';

var metasync = require('./metasync');
var fs = require('fs');

// Data Collector

var dataCollector = new metasync.DataCollector(4, function(data) {
  console.dir(Object.keys(data));
});

dataCollector.collect('user', { name: '<NAME>' });

fs.readFile('HISTORY.md', function(err, data) {
  dataCollector.collect('history', data);
});

fs.readFile('README.md', function(err, data) {
  dataCollector.collect('readme', data);
});

setTimeout(function() {
  dataCollector.collect('timer', { date: new Date() });
}, 1000);

// Functional Asyncronous Composition

metasync.composition(
  [f1,f2,f3,[[f4,f5,[f6,f7],f8]],f9],
  function done(data) {
    console.log('done');
  }
);

function f1(callback) {
  console.log('f1');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f2(callback) {
  console.log('f2');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f3(callback) {
  console.log('f3');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f4(callback) {
  console.log('f4');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f5(callback) {
  console.log('f5');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f6(callback) {
  console.log('f6');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f7(callback) {
  console.log('f7');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f8(callback) {
  console.log('f8');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f9(callback) {
  console.log('f9');
  setTimeout(function() {
    callback();
  }, 1000);
}<commit_msg>Add example of using asynchrous `filter` function<commit_after>'use strict';

var metasync = require('./metasync');
var fs = require('fs');

// Data Collector

var dataCollector = new metasync.DataCollector(4, function(data) {
  console.dir(Object.keys(data));
});

dataCollector.collect('user', { name: '<NAME>' });

fs.readFile('HISTORY.md', function(err, data) {
  dataCollector.collect('history', data);
});

fs.readFile('README.md', function(err, data) {
  dataCollector.collect('readme', data);
});

setTimeout(function() {
  dataCollector.collect('timer', { date: new Date() });
}, 1000);

// Functional Asyncronous Composition

metasync.composition(
  [f1,f2,f3,[[f4,f5,[f6,f7],f8]],f9],
  function done(data) {
    console.log('done');
  }
);

function f1(callback) {
  console.log('f1');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f2(callback) {
  console.log('f2');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f3(callback) {
  console.log('f3');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f4(callback) {
  console.log('f4');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f5(callback) {
  console.log('f5');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f6(callback) {
  console.log('f6');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f7(callback) {
  console.log('f7');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f8(callback) {
  console.log('f8');
  setTimeout(function() {
    callback();
  }, 1000);
}

function f9(callback) {
  console.log('f9');
  setTimeout(function() {
    callback();
  }, 1000);
}

// Asynchrous filter
metasync.filter(
  function(item) {
    // filter words which consists of unique letters only
    var letters = [];
    for (var i = 0; i < item.length; ++i) {
      if (letters.indexOf(item[i].toLowerCase()) > -1) {
        return false;
      }
      letters.push(item[i].toLowerCase());
    }
    return true;
  },
  ['Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 
   'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor',
   'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua',
  ],
  function(result) { console.log(result); }
);

{'fraction_non_alphanumeric': 0.2042235385011589, 'fraction_numerical': 0.035539531290239505, 'mean_word_length': 4.09043250327654, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '6218048', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1401, 'n_words': 250}