jqlang / jq

Command-line JSON processor
https://jqlang.github.io/jq/
Other
29.59k stars 1.54k forks source link

Implement `add/1` #3144

Open myaaaaaaaaa opened 2 weeks ago

myaaaaaaaaa commented 2 weeks ago

Improves the ergonomics of add by avoiding the need for wrapper arrays. Assignments should be easier now too:

-... | .field = ([ ... ] | add) | ...
+... | .field = add(...) | ...

Related to #2595

wader commented 2 weeks ago

I like it. What do other ppl say? from the original issue there was also talk about generator variants of min/max, add those too?

myaaaaaaaaa commented 1 week ago

from the original issue there was also talk about generator variants of min/max, add those too?

Done

pkoppstein commented 1 week ago

Adding a stream-oriented add is long-overdue, so my hope is that its introduction will not be delayed by potentially contentious issues.

Adding stream-oriented versions of min, max, min_by, and max_by would be fine, but it seems to me that existing implementations in C should be retained, both for the sake of efficiency and perhaps to facilitate future C-oriented development.

Maybe the best would be to have one narrowly focused PR for add; and one or more separate ones for the rest.

myaaaaaaaaa commented 1 week ago

It looks like min/1 and max/1 have been attempted before, and met the same concerns regarding jq vs C performance:

Perhaps it would be prudent to discuss the best approach for min/1 and max/1 in #2595 first?

For now, I'll revert this PR to focus solely on add/1