# MapThread over a nested list

I have a nested list

kr = {{35, 32, 27, 20}, {36, 33, 28, 21}, {37, 34, 29, 22}}


I want to use a function flo[x_,y_,z_] on each of the lists after modifying it. So the Mapthread on a given list k0 (eg. {35, 32, 27, 20}) will look like this

MapThread[flo[L, ##] &, {Most@k0, Rest@k0}];


I want the output to look like this.

qfr = {{flo[L,35,32], flo[L,32,27],flo[L,27,20]},{flo[L,36,33],
flo[L,33,28],flo[L,28,21]},{flo[L,37,34], flo[L,34,29],flo[L,29,22]}}


I tried to do the following without much luck. what am I missing?

MapThread[flo[L, ##] &, {Most@#, Rest@#}] & kr

• You're almost there... you just need to Map it on to kr like this: MapThread[flo[L, ##] &, {Most@#, Rest@#}] & /@ kr
– rm -rf
Mar 12, 2014 at 14:37

flo[L, ##] & @@@ Partition[#, 2, 1] & /@ kr

MapThread[flo[L, ##] &, {Most@#, Rest@#}] & /@ kr

Without the /@ you are multiplying the expression MapThread[flo[L, ##] &, {Most@#, Rest@#}] & with every element in kr. The /@ on the opposite uses the expression as a function and applies it to every element in kr treated as a list.