jsonparser icon indicating copy to clipboard operation
jsonparser copied to clipboard

Implementing ArrayEachLimited method.

Open ivahaev opened this issue 9 years ago • 7 comments

I'm not sure of the name, but just wrote implementation of ArrayEach with ability to stop processing array when required value found. To keep the backward compatibility I create new method ArrayEachLimited and ArrayEach uses it internally.

So callback function receives one extra argument – index of element in array and should return bool. If called callback returns false, ArrayEachLimited will stop processing.

What do you think?

ivahaev avatar Aug 10 '16 20:08 ivahaev

In my opinion, it should return an error instead, and that error should be passed through to the caller of ArrayEachLimited.

daboyuka avatar Aug 11 '16 14:08 daboyuka

I thought about error, but in my opinion, error need to return when something went wrong. In this case we just want to tell that no need to iterate more.

ivahaev avatar Aug 11 '16 14:08 ivahaev

True, but error is more versatile. You could return io.EOF to signal "done iterating, no problem" to your outer code.

daboyuka avatar Aug 11 '16 17:08 daboyuka

Sounds good. Waiting for Leonid vote

ivahaev avatar Aug 11 '16 17:08 ivahaev

So, Leonid, what do you think about it?

ivahaev avatar Dec 17 '16 19:12 ivahaev

I think I would prefer to return error, with io.EOF being a clean signal to stop.

ppanyukov avatar Jun 22 '17 12:06 ppanyukov

Currently you can early exit in ObjectEach and I think adding that ability to ArrayEach would also be a good idea. Has there been any progress to resolve the branch conflicts? Are we still waiting @buger to vote?

jimmyjames85 avatar Oct 13 '17 20:10 jimmyjames85