Is there some way I can achieve the distributive property for arrays in `jq`?

I want to multiply 2 arrays to produce a mixed reduce. I compare this to using the FOIL method expanding and distributing parenthesized terms between polynomials into a resulting, combined expression in algebra.

I was hoping to avoid having to write a foreach loop, even if it automatically works for any array length, and doing that for every array mixture I want to create.

I also want to avoid creating some resultant array through iterating the first array, combining the terms from the second array, and then somehow performing a total composition in this filter segment, possibly requiring a flatten directive at the end. This seems like too many steps for what I need, and could be more concisely represented. A * operator perhaps?

I'm starting to think the second method is what I need to do since I may not want to 'multiply' the terms, but instead create a new array or object to use while working with the rest of my task.

My question is starting to sound like essentially asking how to enter a double foreach loop in jq using filters and only the data elements, not that actual foreach loop?

In my example I essentially want to use 2 arrays, each containing a pair of terms to be used in an enumeration of states, to create a resulting array that allows me to iterate through 4 total cases. This is similar to how combinations are calculated.

Does anybody know what I am talking about? :)

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image