Returning early should be implemented via a new `takeWhile` call On Tue, 29 Aug 2017 02:06 Tab Atkins Jr. <[email protected]> wrote:
> On Mon, Aug 28, 2017 at 1:27 PM, Sebastian Malton <[email protected]> > wrote: > > This could be done but I see a few problems with it: > > > > 1. Though it does make ending from some functions like forEach able to > be done it does not all returning from other functions like map or sort > > map() and forEach() have exactly the same signatures for their > callbacks; you can definitely do the same thing in both of them. > > You're right about sort(), but returning early from a sort() call > seems like a really small niche; I think it's the sort of thing you'll > only do in an error situation, in which case throwing is the correct > way to handle it. (On the other hand, returning early from a > forEach() can be due to perfectly normal reasons, the same sorts of > things that cause you to `break` from a loop.) > > > 2. It does not directly allow the returning of values but this might be > rectified by having it be a function that you call and when it calls it > stops any further calls and then returns the first parameter past > > It's the outer function's responsibility to return appropriate values. > A map() call that didn't return an array would cause a lot of > problems; a forEach call that returned something meaningful would be > weird. In either case, it's a bad code smell to try and override what > the outer function is doing. If you're stopping because of an error, > and so whatever the function is trying to do isn't relevant anymore, > you should throw an error instead. > > ~TJ > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

