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

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

    Hmm... a counterpoint.

    (`ap` tail) . zipWith
    

    doesn't deserve a name.

    BTW, quicksilver says:

     zip`ap`tail
    

    The Aztec god of consecutive numbers

    0 讨论(0)
  • 2021-02-06 00:24

    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

    0 讨论(0)
  • 2021-02-06 00:24

    BinaryOperate or BinaryMerge

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-06 00:27

    in C++ Standard Template Library, it is called adjacent_difference (though the operator can be any operation, not just subtraction)

    0 讨论(0)
  • 2021-02-06 00:29

    I vote for smearWith or smudgeWith because it's like you are smearing/smudging the operation across the list.

    0 讨论(0)
提交回复
热议问题