<commit_before>
# foreach

  iterate over key value pairs (array or object). async or sync implementations

## Getting Started

_With component_  

  $ component install jkroso/foreach

_With npm_  

  $ npm install jkroso/foreach --save

then in your app:

```js
var foreach = require('foreach')
var async = require('foreach/async')
var series = require('foreach/series')
```

## API

- [foreach()](#foreach)
- [async()](#async)
- [series()](#series)

### foreach(object, iterator, context)

  apply iterator to each key value pair in `object`. The value is passed as the first argument and the key as the second. If you pass `context` that will be the value of `this` inside of `iterator`.

```js
foreach({a:1,b:2}, function(v, k){
  // v = 1,2
  // k = a,b
})
foreach([1,2], function(v, k){
  // v = 1,2
  // k = 0,1
})
```

### async()

  Same API as the sync version except it will return a promise object, which will either, resolve when all items have been processed or reject when one rejects. No ordering is guaranteed between items. If `iterator` takes a 3rd argument it is expected to be a callback function.

```js
async([1,2,3], function(value, i, done){
  setTimeout(done, i)
}).then(function(){
  // runs after all async processes have called `done`
})
```

### series()

  Like `async` but the next item will not be processed until the previous one completes

## Running the tests

```bash
$ npm install
$ make
```
Then open your browser to the `./test` directory.

_Note: these commands don't work on windows._ 

## License 

[MIT](License)<commit_msg>example<commit_after>
# foreach

  iterate over key value pairs (array or object). async or sync implementations

## Getting Started

_With component_  

  $ component install jkroso/foreach

_With npm_  

  $ npm install jkroso/foreach --save

then in your app:

```js
var foreach = require('foreach')
var async = require('foreach/async')
var series = require('foreach/series')
```

## API

- [foreach()](#foreach)
- [async()](#async)
- [series()](#series)

### foreach(object, iterator, context)

  apply iterator to each key value pair in `object`. The value is passed as the first argument and the key as the second. If you pass `context` that will be the value of `this` inside of `iterator`.

```js
foreach({a:1,b:2}, function(v, k){
  // v = 1,2
  // k = a,b
})
foreach([1,2], function(v, k){
  // v = 1,2
  // k = 0,1
})
```

### async()

  Same API as the sync version except it will return a promise object, which will either, resolve when all items have been processed or reject when one rejects. No ordering is guaranteed between items. If `iterator` takes a 3rd argument it is expected to be a callback function.

```js
async([20, 10, 0], function(value, i, done){
  setTimeout(done, value)
}).then(function(){
  // This function runs after all async processes have called `done`.
  // Note that in this example the last iteration will complete before
  // the first because all iterations are run in parrallel and the last 
  // one completes in the shortest time
})
```

### series()

  Like `async` but the next item will not be processed until the previous one completes

## Running the tests

```bash
$ npm install
$ make
```
Then open your browser to the `./test` directory.

_Note: these commands don't work on windows._ 

## License 

[MIT](License)
{'fraction_non_alphanumeric': 0.12488769092542677, 'fraction_numerical': 0.008984725965858042, 'mean_word_length': 3.805755395683453, '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': '7672032', 'n_tokens_mistral': 1050, 'n_tokens_neox': 978, 'n_words': 442}