Answer the question
In order to leave comments, you need to log in
Why use functor?
Thank you for your attention! Tell me, what is the advantage of a functor, because it will simply apply the function on the value stored in the object? We could do this before without an object (new to FP). Don't scold me if this is a dumb question :)
Answer the question
In order to leave comments, you need to log in
A functor, in the context of functional programming, is an interface (or typeclass) that can be implemented for different types. In order for a type to implement a functor, it must have a kind * -> *
(that is, it must be a generic with one parameter) and a function must be implemented for it map
:
The name and signature may differ depending on the implementation, for example, in Haskell this function is called , and in Fantasy Land the signature looks like this: Also , certain laws must be observed
for the function / method , I will not copy them here, I will just leave the link: https://github.com/fantasyland/fantasy-land#functor
A few examples of functors:
Array
- map
applies a function to each element of the array.Future
- map
applies the function to the value when it resolves.Maybe
- map
applies the function to the value if it exists, otherwise returns Nothing
.Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question