I am trying to name what I think is a new idea for a higher-order function. To the important part, here is the code in Python and Haskell to demonstrate the concept, which will
Hmm... a counterpoint.
(`ap` tail) . zipWith
doesn't deserve a name.
BTW, quicksilver says:
zip`ap`tail
The Aztec god of consecutive numbers
Here's another implementation for Python which works if l
is a generator too
import itertools as it
def apply_pairwise(f, l):
left, right = it.tee(l)
next(right)
return it.starmap(f, it.izip(left, right))
I think apply_pairwise
is a better name
BinaryOperate or BinaryMerge
Using Mathematica
Plus @@@ Partition[{0, 1, 2, 3}, 2, 1] or either of these more verbose alternatives
Apply[Plus, Partition[{0, 1, 2, 3}, 2, 1], {1}]
Map[Apply[Plus, #] &, Partition[{0, 1, 2, 3}, 2, 1]]
I have used and enjoyed this higher order function in many languages but I have enjoyed it the most in Mathematica; it seems succinct and flexible broken down into Partition and Apply with levelspec option.
in C++ Standard Template Library, it is called adjacent_difference (though the operator can be any operation, not just subtraction)
I vote for smearWith
or smudgeWith
because it's like you are smearing/smudging the operation across the list.