What do we call this (new?) higher-order function?

后端 未结 16 1685
盖世英雄少女心
盖世英雄少女心 2021-02-05 23:44

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

16条回答
  •  孤街浪徒
    2021-02-06 00:30

    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.

提交回复
热议问题