Is there a built-in or more efficient approach than using Partition
to apply a binary operation to adjacent pairs of elements? That is, is it reasonable to be using the following for a binary operation f
and a possibly long list (here, just {a,b,c}
) the following approach?
Map[f @@ # &, Partition[{a, b, c}, 2, 1]]
Related: will the result of this use of Partition
ever actually be constructed in full, or are the pairs just generated on demand? (And how can I anticipate the answer to this question?)
f @@ list[[# ;; # + 1]] & /@ Range[Length[list] - 1]
$\endgroup$l = {a, b, c}; Inner[f, Most@l, Rest@l, List]
$\endgroup$Most
andRest
, I can just useThread
. But that gets me back to my question of how I can know when such things will be constructed. $\endgroup$Map[f @@ # &, Partition[{a, b, c}, 2, 1]] // Trace
$\endgroup$Map
has noHold*
attributes so the fullPartition
will be evaluated before Map sees it. The pairs are not generated on demand. $\endgroup$