All the good JS folks are into Functional Programming these days. Many of my readers already know about the Monad, and its other Functor friends. But what about that other similar word that you’ll occasionally see — Monoid. Monoid is a bit more elusive on the web than Monad. You won’t find quite as much good material on the topic. But, they’re still an important part of the category theory of FP.

Monoids encapsulate a binary operation.

The way I like to think of a Monoid is the encapsulation of a binary operation. You can concatenate Monoid instances to yield a new Monoid with a merged underlying value. You can also reduce them into their underlying values, much like the Monad _unwrap. _Let’s try hand-rolling a few Monoids to understand what they’re all about. We’ll start with a fun one that exists for languages that have objects — here’s a JavaScript Assign:

Image for post

#javascript #technology #programming #software-development #data-science

What is a Monoid?
1.20 GEEK