Monoid, Functor, Applicative and Monad
I’m going to just write down the note for myself to remember
==========================
Monoid = A -> A -> A
List.concat()
List<A> -> List<A> -> List<A>
Add(a, b)
Number -> Number -> Number
==========================
Functor = (A -> B) -> F<A> -> F<B>
List.map()
(A -> B) -> List<A> -> List<B>
Promise.map()
(A -> B) -> Promise<A> -> Promise<B>
==========================
Applicative = F<A -> B> -> F<A> -> F<B>
List.apply()
List<A -> B> -> List<A> -> List<B>
Promise.apply()
Promise<A -> B> -> Promise<A> -> Promise<B>
==========================
Monad = (A -> F<B>) -> F<A> -> F<B>
List.flatMap()
(A -> List<B>) -> List<A> -> List<B>
Promise.flatMap()
(A -> Promise<B>) -> Promise<A> -> Promise<B>
==========================
All 3 are essentially the pattern to transform FA -> FB with different morphism
Functor -> map with no additional computation (side effects)
Applicative-> apply with additional computation before mapping
Monad -> chain with additional computation after mapping
They are just ways to define the structure of computation, not implementation, that depends on the context.