Throwing StopIteration in array extras to stop the iteration

Domenic Denicola domenic at
Mon Mar 4 12:21:37 PST 2013

From: es-discuss-bounces at [es-discuss-bounces at] on behalf of Rick Waldron [waldron.rick at]

> Thanks, I've submitted an agenda item that includes _both_ find and findIndex.


One issue with `find` is what distinguishes

    find([1, 2, 3], x => isNaN(x)); // presumably `undefined`


    find([1, 2, undefined, 3], x => isNaN(x)); // also presumably `undefined`

i.e. how do you distinguish "found nothing" from "found `undefined`."

In C# they have `IEnumerable<T>.First` and `IEnumerable<T>.FirstOrDefault`; the former throws an error if nothing matching the predicate is found, whereas the latter returns `default(T)` (which is `null` for reference types, or `0` for numbers, etc.).

Food for thought.

More information about the es-discuss mailing list