DEV Community

Marant7
Marant7

Posted on

Understanding how programming works using Functors, Monads, and Promises

1.FUNCTORS

Functors are data structures that can be mapped over with a function. This means you can apply a function to the values inside a functor, producing a new functor with the transformed values.

Image description

2.Promises

Promises are a fundamental concept in asynchronous programming in JavaScript. They represent the eventual completion (or failure) of an asynchronous operation and allow handling its result asynchronously. A promise can be in one of three states: pending, fulfilled, or rejected. When a promise is fulfilled, it means the asynchronous operation has successfully completed, and you can access the result using .then(). If it's rejected, it means an error occurred, and you can handle it using .catch(). Promises are chainable, which means you can use .then() to chain asynchronous operations one after another, facilitating sequential execution in an asynchronous environment.

Image description

3.Monads
Monads are structures in functional programming that facilitate handling side effects and function composition. They have two main operations: unit, which wraps a value in a monad, and bind, which allows chaining operations while handling the monadic context. Monads provide a way to encapsulate values with side effects or values that can be null, avoiding common issues such as null or undefined.

Image description

Top comments (0)