pure functional state: pt. i

Managing a programs state is a necessary evil, particularly so in Restful API’s. This post explores how to create predictable testable and modular functionality for state-ful domain logic in a purely functional manner. A naive solution to a problem like this in a different programming paradigm might be to create some kind of state monitoring and management module to harness a piece of data’s state, however our solution will be to separate concerns of computing the new state and communicating to the rest of the aplication what that state is by returning both the new state-ful piece of data along with the derived values the state is responsible for computing. This way we can avoid a shared mutable memory by returning to the caller the next state leaving the previous state in tact.