Throwing StopIteration in array extras to stop the iteration
bruant.d at gmail.com
Tue Mar 5 11:05:31 PST 2013
Le 05/03/2013 17:37, Brendan Eich a écrit :
> David Bruant wrote:
>> I'm happy of the outcome of the thread if .findIndex is introduced,
>> but I can't help wondering whether a new method is going to be
>> introduced every single time someone brings up a pattern that would
>> make good use of stopping an interation early.
> Lacking an iteration protocol, that's the natural tendency, although
> there are only so many methods and method-variations likely to be needed.
> With for-of, stopping early is done by a break in the body.
Indeed. The mention of the lack of an iteration protocol made me realize
that maybe .forEach was just a detour (map/reduce/filter/every/some
answer to a specific pattern, so they're still useful)
> Inventing synonyms for exceptions (endframe) or adding escape
> continuations for more locally structured control effects could be
> done, but why? I think we're nearly "done" (no pun!).
Discriminating how a frame ended by value works. There is the concern
about cross-frame protocols and we're saved by [[Brand]] which is a
forgeable string that's the same cross-globals.
But authors don't have this kind of control.
protocols because hacking "return true/false" (considered so many times
for proxy traps) and "throw StopIteration" will be enough.
I don't have a better name than "function-based protocols", but I feel
we're not done with them. We might be just starting. We'll see.
More information about the es-discuss