2 ms·
FP is best paired with a type system. If you're not using Typescript, then functional Javascript can be hard to follow. The reason is that without types, usage
by phailhaus 5y ago
FP is best paired with a type system. If you're not using Typescript, then functional Javascript can be hard to follow. The reason is that without types, usage of functions like `map` require you to grok the implementation details of the callback, so that you can understand what the resulting object looks like, and then you have to hold that type in your head going forward.
When you're using a typed language, it's just that: an implementation detail. All that matters is the type you get out, so you can start ignoring all those details and just focus on your program at a higher level, like "first we start with an array of id's, then we map that into an array of employees, then we reduce it into a sum". Much harder to make a mistake compared to "okay, I'm going to maintain a running counter. Then, within a loop, take an id and find the employee, then add the employee's salary to the running sum. After all this I should have a total salary value".