In Functional Programming, what is a functor?

后端 未结 17 665
孤独总比滥情好
孤独总比滥情好 2020-11-28 17:23

I\'ve come across the term \'Functor\' a few times while reading various articles on functional programming, but the authors typically assume the reader already understands

17条回答
  •  温柔的废话
    2020-11-28 17:52

    Other answers here are complete, but I'll try another explanation of the FP use of functor. Take this as analogy:

    A functor is a container of type a that, when subjected to a function that maps from ab, yields a container of type b.

    Unlike the abstracted-function-pointer use in C++, here the functor is not the function; rather, it's something that behaves consistently when subjected to a function.

提交回复
热议问题