You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reduce .[] as $a ([]; if IN(.[]; $a) then . else . += [$a] end)
221
221
;
222
-
reduce .[] as $in ({};
222
+
def meld($o):
223
+
# recursive merge of objects like "*", but also append lists (uniquely) instead of replace
224
+
# https://stackoverflow.com/a/53666584, but with lists unique-ified and less work being done
225
+
if type == "object" and ($o | type) == "object" then
226
+
reduce ($o | keys_unsorted[]) as $k (.;
227
+
.[$k] |= meld($o[$k])
228
+
)
229
+
elif type == "array" and ($o | type) == "array" then
230
+
. + $o
231
+
| unique_unsorted
232
+
elif $o == null then
233
+
.
234
+
else
235
+
$o
236
+
end
237
+
;
238
+
(
239
+
# creating a lookup of .[tag][arch] to a list of sourceIds
240
+
[
241
+
.[] as $s
242
+
| ( $s.arches[] | .tags[], .archTags[] )
243
+
| {
244
+
key: .,
245
+
# this happens pre-arches-merge, so it is only one arch
246
+
value: { ($s.arches | keys[]): [$s.sourceId] },
247
+
}
248
+
]
249
+
# do not try to code golf this to one reduce without from_entries or group_by; doing ".[xxx] |=" on the *full* unordered object gets orders of magnitude slower
250
+
| group_by(.key)
251
+
| [
252
+
# many little reduces based on same key (group_by^), instead of one very big and expensive
0 commit comments