Using State
Explore how to apply the State monad in TypeScript functional programming using fp-ts. Understand managing state immutably in a reservation app, keep purity using seed values, and integrate StateTaskEither for complex workflows.
We'll cover the following...
We use a Reader to pass the configuration on to multiple functions. The railway model of always enriching our object with additional required information is an orderly way of thinking about functional programs. It means that we can avoid keeping the state within our application. That is, we don’t have to know that our request is now in the processed state or that information is contained within the object’s name, type, or properties. In some cases, though, we’ll need to keep State. This is why we use objects in OOP. How do we go about doing that in a functional language? Enter the State monad.
State monad
In essence, State provides a way for us to keep an object or value, which can be used and changed by our function. A classic example of the use of State is producing a random value. The way we generate a random number ...