There are a number of questions on this site about "threading" including several relating to uneven (ragged) lists. However, none that I could find deal with the full functionality of Thread
but instead things like MapThread
, or the ragged transpose of Flatten[expr, {2}]
.
Thread
operates:
Inside held expressions without errant evaluation
On arbitrary heads as specified with the second parameter
By distributing singlets across all subexpressions
On only the first n arguments (subexpressions) if given as third parameter
For example:
expr = Hold[qq[2 + 2, 1/0, 8/4], qq[1, 2, 3], Sqrt[2 + 2]];
Thread[expr, qq]
Thread[expr, qq, 1]
qq[Hold[2 + 2, 1, Sqrt[2 + 2]], Hold[1/0, 2, Sqrt[2 + 2]], Hold[8/4, 3, Sqrt[2 + 2]]] qq[Hold[2 + 2, qq[1, 2, 3], Sqrt[2 + 2]], Hold[1/0, qq[1, 2, 3], Sqrt[2 + 2]], Hold[8/4, qq[1, 2, 3], Sqrt[2 + 2]]]
All of this breaks if we change qq[1, 2, 3]
to qq[1, 2]
.
What is the most efficient way to extend Thread
to ragged subexpressions?