# Enumerable


This is bound to DOM objects:

                  
global('p').each(function() {
  // `this` contains a DOM element
});         
                  
                

Iterates using a function over a set of items. Example:

                  
Siga.enumerable.each([1, 2, 3], function(n) {
   console.log(n);
 });         
                  
                

You can Change a set of item using a function. Example:

                  
Siga.enumerable.each([1, 2, 3], function(n) {
   console.log(n);
 });         
                  
                

Changes a set of item using a function. Example:

                  
Siga.enumerable.map([1, 2, 3], function(n) {
   return n + 1;
 });         
                  
                

You can Removes items based on a callback. For example:

                  
var a = [1, 2, 3, 4, 5, 6, 7, 8];
 Siga.enumerable.filter(a, function(n) {
   return n % 2 === 0;
 });

 => [2, 4, 6, 8]        
                  
                

The opposite of filter. For example:

                  
var a = [1, 2, 3, 4, 5, 6, 7, 8];
 Siga.enumerable.reject(a, function(n) {
   return n % 2 === 0;
 });

 => [1, 3, 5, 7]       
                  
                

Find a single item. For example:

                  
 var a = [1, 2, 3, 4, 5, 6, 7, 8];
 Siga.enumerable.detect(a, function(n) {
   return n === 3;
 });

 => 3      
                  
                

Runs a function over each item, collecting the results:

                  
 var a = [1, 2, 3, 4, 5, 6, 7, 8];
 Siga.enumerable.reduce(a, 0, function(memo, n) {
   return memo + n;
 });

 => 36    
                  
                

Flattens multidimensional arrays:

                  
Siga.enumerable.flatten([[2, 4], [[6], 8]]);

 => [2, 4, 6, 8]   
                  
                

Return the last items from a list:

                  
Siga.enumerable.tail([1, 2, 3, 4, 5], 3);

 => [4, 5]   
                  
                

Invokes method on a list of items:

                  
Siga.enumerable.invoke(['hello', 'world'], 'substring', 0, 3);

 => ['hel', 'wor']   
                  
                

Pluck a property from each item of a list:

                  
Siga.enumerable.pluck(['hello', 'world'], 'length');

 => [5, 5]   
                  
                

Determines if a list matches some items based on a callback:

                  
Siga.enumerable.some([1, 2, 3], function(value) {
   return value === 3;
 });

 => true   
                  
                

Checks if all items match the callback:

                  
 Siga.enumerable.all([1, 2, 3], function(value) {
   return value < 4;
 })

 => true  
                  
                

Checks if one item matches a value:

                  
 Siga.enumerable.include([1, 2, 3], 3);

 => true  
                  
                

Chain enumerable calls:

                  
siga.enumerable.chain([1, 2, 3, 4])
   .filter(function(n) { return n % 2 == 0; })
   .map(function(n) { return n * 10; })
   .values();

 => [20, 40]