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

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

    So because there seems to be no name for this I suggest 'merger' or simple 'merge' because you are merging adjacent values together.

    So merge is already taken so I now suggest 'meld' (or 'merger' still but that may be too close to 'merge')

    For example:

    meld :: (a -> a -> b) -> [a] -> [b]
    meld _ [] = []
    meld f xs = zipWith f (init xs) (tail xs)
    

    Which can be used as:

    > meld (+) [1..10]
    [3,5,7,9,11,13,15,17,19]
    > meld compare "hello world"
    [GT,LT,EQ,LT,GT,LT,GT,LT,GT,GT]
    

    Where the second example makes no real sense but makes a cool example.

提交回复
热议问题