Class Pot.Iter
Defined in: <potlite.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Pot.Iter()
Iter.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
Pot.Iter.StopIteration
StopIteration.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Pot.Iter.every(object, callback, (context))
Tests whether all elements in the object pass the
test implemented by the provided function.
|
<static> |
Pot.Iter.filter(object, callback, (context))
Creates a new object with all elements that
pass the test implemented by the provided function.
|
<static> |
Pot.Iter.indexOf(object, subject, (from))
Returns the first index at which a
given element can be found in the object, or -1 if it is not present.
|
isIter()
isIter.
|
|
<static> |
Pot.Iter.lastIndexOf(object, subject, (from))
Returns the last index at which a
given element can be found in the object, or -1 if it is not present.
|
<static> |
Pot.Iter.map(object, callback, (context))
Creates a new object with the results of calling a
provided function on every element in object.
|
next()
Abstract function.
|
|
<static> |
Pot.Iter.range(end/begin, (end), (step))
Create continuously array that
has numbers between start number and end number.
|
<static> |
Pot.Iter.reduce(object, callback, (initial), (context))
Apply a function against an accumulator and each value of
the object (from left-to-right) as to reduce it to a single value.
|
<static> |
Pot.Iter.some(object, callback, (context))
Tests whether some element in the object passes the
test implemented by the provided function.
|
<static> |
Pot.Iter.toIter(x)
Assign to an iterator from the argument object value.
|
toString()
toString.
|
Class Detail
Pot.Iter()
Iter.
A Simple iterator.
Constructor.
- Parameters:
- {*} Options.
- Returns:
- {Pot.Iter} Returns an instance of Pot.Iter
Field Detail
<static>
{Object}
Pot.Iter.StopIteration
StopIteration.
Method Detail
<static>
{Function}
Pot.Iter.every(object, callback, (context))
Tests whether all elements in the object pass the
test implemented by the provided function.
This method like Array.prototype.every
function isBigEnough(value, index, array) { return (value >= 10); } var passed = Pot.Iter.every([12, 5, 8, 130, 44], isBigEnough); debug(passed); // passed is false passed = Pot.Iter.every([12, 54, 18, 130, 44], isBigEnough); debug(passed); // passed is true
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (context)
- (Optional) Object to use as `this` when executing callback.
- Returns:
- {Boolean} Return the Boolean result by callback.
<static>
{Function}
Pot.Iter.filter(object, callback, (context))
Creates a new object with all elements that
pass the test implemented by the provided function.
This method like Array.prototype.filter
function isBigEnough(value, index, array) { return (value >= 10); } var filtered = Pot.Iter.filter([12, 5, 8, 130, 44], isBigEnough); debug(filtered); // @results [12, 130, 44]
function isBigEnough(value, key, object) { return (value >= 10); } var object = {a: 1, b: 20, c: 7, d: 5, e: 27, f: 99}; var result = Pot.Iter.filter(object, isBigEnough); debug(result); // @results {b: 20, e: 27, f: 99}
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (context)
- (Optional) Object to use as `this` when executing callback.
- Returns:
- {*} Return the result of each callbacks.
<static>
{Function}
Pot.Iter.indexOf(object, subject, (from))
Returns the first index at which a
given element can be found in the object, or -1 if it is not present.
This method like Array.prototype.indexOf
var array = [2, 5, 9]; var index = Pot.Iter.indexOf(array, 2); // index is 0 index = Pot.Iter.indexOf(array, 7); // index is -1 var object = {a: 2, b: 5, c: 9}; index = Pot.Iter.indexOf(object, 2); // index is 'a' index = Pot.Iter.indexOf(object, 7); // index is -1
- Parameters:
- {Array|Object|*} object
- A target object.
- {*} subject
- A subject object.
- {*} (from)
- (Optional) The index at which to begin the search. Defaults to 0.
- Returns:
- {Number|String} Return the index of result, or -1.
{Function}
isIter()
isIter.
<static>
{Function}
Pot.Iter.lastIndexOf(object, subject, (from))
Returns the last index at which a
given element can be found in the object, or -1 if it is not present.
This method like Array.prototype.lastIndexOf
debug('array'); var index, array = [2, 5, 9, 2]; index = Pot.Iter.lastIndexOf(array, 2); debug('index is 3 : result = ' + index); // 3 index = Pot.Iter.lastIndexOf(array, 7); debug('index is -1 : result = ' + index); // -1 index = Pot.Iter.lastIndexOf(array, 2, 3); debug('index is 3 : result = ' + index); // 3 index = Pot.Iter.lastIndexOf(array, 2, 2); debug('index is 0 : result = ' + index); // 0 index = Pot.Iter.lastIndexOf(array, 2, -2); debug('index is 0 : result = ' + index); // 0 index = Pot.Iter.lastIndexOf(array, 2, -1); debug('index is 3 : result = ' + index); // 3 debug('object'); var object = {a: 2, b: 5, c: 9, d: 2}; index = Pot.Iter.lastIndexOf(object, 2); debug('index is d : result = ' + index); // 'd' index = Pot.Iter.lastIndexOf(object, 7); debug('index is -1 : result = ' + index); // -1 index = Pot.Iter.lastIndexOf(object, 2, 'd'); // 'd' debug('index is d : result = ' + index); index = Pot.Iter.lastIndexOf(object, 2, 'c'); // 'a' debug('index is a : result = ' + index);
- Parameters:
- {Array|Object|*} object
- A target object.
- {*} subject
- A subject object.
- {*} (from)
- (Optional) The index at which to start searching backwards. Defaults to the array's length.
- Returns:
- {Number|String} Return the index of result, or -1.
<static>
{Function}
Pot.Iter.map(object, callback, (context))
Creates a new object with the results of calling a
provided function on every element in object.
This method like Array.prototype.map
function fuzzyPlural(single) { return single.replace(/o/g, 'e'); } var words = ['foot', 'goose', 'moose']; debug(Pot.Iter.map(words, fuzzyPlural)); // @results ['feet', 'geese', 'meese']
var object = {foo: 'foo1', bar: 'bar2', baz: 'baz3'}; var result = Pot.Iter.map(object, function(value, key) { return value + '00'; }); debug(result); // @results {foo: 'foo100', bar: 'bar200', baz: 'baz300'}
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (context)
- (Optional) Object to use as `this` when executing callback.
- Returns:
- {*} Return the result of each callbacks.
{Function}
next()
Abstract function.
Note: Firebug 1.7.x never shows the name of "next" method.
<static>
{Function}
Pot.Iter.range(end/begin, (end), (step))
Create continuously array that
has numbers between start number and end number.
First argument can given an object that has "begin, end, step" any keys.
This function can be a letter rather than just numbers.
var numbers = Pot.Iter.range(1, 5); debug(numbers); // @results [1, 2, 3, 4, 5] var chars = Pot.Iter.range('a', 'f'); debug(chars); // @results ['a', 'b', 'c', 'd', 'e', 'f'] var ranges = Pot.Iter.range({begin: 0, step: 10, end: 50}); debug(ranges); // @results [0, 10, 20, 30, 40, 50]
- Parameters:
- {Number|Object} end/begin
- The end number or object.
- {Number} (end)
- (optinal) The end number.
- {Number} (step)
- (optinal) The step number.
- Returns:
- {Array} Return an array result.
<static>
{Function}
Pot.Iter.reduce(object, callback, (initial), (context))
Apply a function against an accumulator and each value of
the object (from left-to-right) as to reduce it to a single value.
This method like Array.prototype.reduce
var array = [1, 2, 3, 4, 5]; var total = Pot.Iter.reduce(array, function(a, b) { return a + b; }); debug(total); // @results 15
var object = {a: 1, b: 2, c: 3}; var total = Pot.Iter.reduce(object, function(a, b) { return a + b; }); debug(total); // @results 6
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (initial)
- An initial value passed as `callback` argument that will be used on first iteration.
- {*} (context)
- (Optional) Object to use as the first argument to the first call of the `callback`.
- Returns:
- {*} Return the result of each callbacks.
<static>
{Function}
Pot.Iter.some(object, callback, (context))
Tests whether some element in the object passes the
test implemented by the provided function.
This method like Array.prototype.some
function isBigEnough(value, index, array) { return (value >= 10); } var passed = Pot.Iter.some([2, 5, 8, 1, 4], isBigEnough); debug(passed); // passed is false passed = Pot.Iter.some([12, 5, 8, 1, 4], isBigEnough); debug(passed); // passed is true
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (context)
- (Optional) Object to use as `this` when executing callback.
- Returns:
- {Boolean} Return the Boolean result by callback.
<static>
{Function}
Pot.Iter.toIter(x)
Assign to an iterator from the argument object value.
- Parameters:
- {*} x
- An iterable object.
- Returns:
- {Pot.Iter} An iterator object instance.
{Function}
toString()
toString.
- Returns:
- Return formatted string of object.