I'd say every and other methods like that should take another argument
that specifies the number if times to test.

You could say that every returns:
- true if the generator is finite and the function always returned true
- false if one of the finite (either because the generator is or
because a number was given as argument) number of calls of the
function returned false
- undefined if the generator is infinite and none of the finite number
of calls returned false

OR

return a generator that tests a new value and returns either true or
false every time it is called
on the nth call, it tests n values




map and filter clearly would be very useful. I'm not sure about the others.

On Sat, Feb 4, 2012 at 10:06 PM, Michael A. Smith <mich...@smith-li.com> wrote:
> Sorry for the resend. Meant to include the list.
>
> I like this idea a lot! However, what would be the correct behavior of
> a method like 'every' on an infinite generator?
>
> -Michael A. Smith
>
>
>
> On Fri, Feb 3, 2012 at 3:54 PM, Domenic Denicola
> <dome...@domenicdenicola.com> wrote:
>> ES5's existing array extras make working with arrays a joy.
>>
>> However, sometimes arrays are not the right tool for the job. Perhaps you 
>> want lazy evaluation semantics (generators). Or perhaps you want to 
>> communicate that the list is immutable (compare .NET's `IEnumerable<T>` or 
>> Java's `Iterable<T>`). ES Harmony seems to have the answer: iterators! Like 
>> `IEnumerable<T>` or `Iterable<T>`, they are the most basic primitive of 
>> iteration. Yay!
>>
>> But, if my `fetchAllProducts()` method returns an iterator, I don't get my 
>> array extras. Sad.
>>
>> ---
>>
>> This may be solvable in library-space, but the iterator proposal doesn't 
>> seem to have an Iterator.prototype I could extend. So we end up with 
>> unfortunate underscore-style wrappers:
>>
>> _(iterator).chain().map(mapper).some(predicate).value()
>> _.some(_.map(iterator, mapper), predicate)
>>
>> I propose adding the array extras to any iterator (in some way), such that 
>> we can have syntax similar to the following:
>>
>> iterator.map(mapper).some(predicate) // returns an iterator
>>
>> The methods I would like to see are:
>> * every, filter, forEach, map, reduce, reduceRight, some
>> * Optionally: join, toString
>> * Controversially: sorted, reversed (non-mutating versions of sort and 
>> reverse)
>>
>> What do you think?
>>
>> -Domenic
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to