11
$\begingroup$

Namely, while

Thread @ f[{a, b}, {x, y}]

gives

{f[a, x], f[b, y]}

the InverseThread (if it existed) should reverse the process that

InverseThread @ {f[a, x], f[b, y]}

gives

f[{a, b}, {x, y}] 
$\endgroup$
  • 17
    $\begingroup$ Thread[{f[a, x], f[b, y]}, f]. $\endgroup$ – Szabolcs Nov 1 '16 at 9:13
14
$\begingroup$

Let's make this a little more challenging:

invThread[body : _[h_[___] ..]] :=
  Replace[Thread[body, h], _[x_ ..] :> x, {1}]

f[{a, b}, {x, y}, z];
% // Thread
% // invThread
{f[a, x, z], f[b, y, z]}

f[{a, b}, {x, y}, z]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.