I’m building a distributed event sourcing system in node. The part I’m focusing on now, is the event dispatcher. It receives events from the eventstore, determines if they are relevant and hands them to the appropriate eventhandler.
While I have already written the piece, I wrote it in an OO manner with inheritance, fancy es6 features, and lots of imperative code. I found that there were so many small pieces of fairly simple logic, that it was very easy to make mistakes or miss possible error scenarios. I wrote shit tons of logging code and ran complex unit and integration tests and watched the logging output.
My pain points were lots of if-then logic, lots of null check logic, lots of stream parsing logic, lots of objects with state and functionality, and trouble with inheritance using es6 classes.
Functional programming, as I started reading up on it, addressed each of these issues.
Using Maybe I avoided ( deferred and centralized really ) if-then logic and null check logic, and error handling . My functions were more numerous, but smaller, stateless and easy to test. I found that I could build up a workflow reusing the composite pieces then simply call the function rather than invoke the behavior from the various pieces that contained the state. As I was not mutating state this also reduced the mental overhead of the app.