In Functional Programming, what is a functor?

后端 未结 17 663
孤独总比滥情好
孤独总比滥情好 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 18:01

    KISS: A functor is an object that has a map method.

    Arrays in JavaScript implement map and are therefore functors. Promises, Streams and Trees often implement map in functional languages, and when they do, they are considered functors. The map method of the functor takes it’s own contents and transforms each of them using the transformation callback passed to map, and returns a new functor, which contains the structure as the first functor, but with the transformed values.

    src: https://www.youtube.com/watch?v=DisD9ftUyCk&feature=youtu.be&t=76

提交回复
热议问题