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
In Python the meld
equivalent is in the itertools receipes and called pairwise.
from itertools import starmap, izp, tee
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
So I would call it:
def pairwith(func, seq):
return starmap(func, pairwise(seq))
I think this makes sense because when you call it with the identity function, it simply returns pairs.