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

后端 未结 16 1681
盖世英雄少女心
盖世英雄少女心 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:12

    Since it's similar to "fold" but doesn't collapse the list into a single value, how about "crease"? If you keep "creasing", you end up "folding" (sort of).

    We could go with a cooking metaphor and call it "pinch", like pinching the crust of a pie, though this might suggest a circular zipping, where the last element of the list is paired with the first.

    def pinch(f, l):
        return map(lambda t: f(*t), zip(l, l[1:]+l[:1]))
    

    (If you only like one of "crease" or "pinch", please note so as a comment. Should these be separate suggestions?)

提交回复
热议问题