Hudson, Rick
unread,Dec 18, 2012, 10:43:31 AM12/18/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Hudson, Rick, dev-tech-js-en...@lists.mozilla.org
>From our notes:
4) change how filter works
- Niko would prefer filter to take a function instead of an array
- would allow for parallel construction of filter vector
- also closer to Array.map
- agreement: change filter to take the same elemental function as map
- AR: Rick update strawman on ECMA wiki
---end notes---
Below is the new filter description in the strawman. It uses a simple elementalFunction and operates on the top level elements. I believe this is what we agreed to last week.
- Rick
filter
Synopsis
myArray.filter(elementalFunction)
Arguments
elementalFunction described below.
Elemental Function
function (element, index, source)
element The element from the ParallelArray.
index The index in source where element is located.
source The ParallelArray holding the elements.
If the result of the function is truthy then the corresponding element will be placed in filter's result. Elements in the result will be in the same order as in the source.
Returns
A freshly minted ParallelArray holding the source elements located at myArray[i] for which elementalFunction returns a truthy value. The order of the elements in the returned ParallelArray is the same as the order of the elements in the source ParallelArray.
Throws
TypeError when elementalFunction is not a function.
Error when elementalFunction has side-effects.
Examples
identity function
var pa = new ParallelArray([1,2,3,4,5,6,7]);
var result = pa.filter(function(ignore){return true;});
filter out every other element
var pa = new ParallelArray([1,2,3,4,5,6,7]);
var result = pa.filter(function(element, index) { return index%2?false:true;} );