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

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

    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.

提交回复
热议问题