Jason Warner
1 min readJun 17, 2022

--

In the day-to-day code, most devs will encounter, iterators are good enough. They serve a purpose and communicate intent. Some problems have been mentioned multiple times that are worth considering. This is your job as a developer. You are deciding when "good enough" makes sense, or you must go for a more performant or otherwise "better" solution. There are always trade-offs in programming. Each approach comes with a list of pros and cons. Very rarely is one approach always correct. It is good to be aware of both sides of an argument and why you chose your side. However, it is also vital to be willing to learn and change sides when presented with superior information. Passion is important. Zealotry will kill your career.

Now that I've written a novel let's talk about functional solutions to this problem. Both ramda and fp-ts have solutions to multiple loops. Functional pipelines allow you to use map, filter, reduce, etc., in a single loop. In ramda, pipe() does left to right composition and compose() does right to left composition. In fp-ts pipe() and flow() are used for function composition. By using currying and partial application, you can also build your own functional chaining operators. With the addition of operators like take(), you can bail early after a certain number of items have been calculated.

I'm not arguing that functional is a silver bullet. I want to point out that being aware of your options and when to apply them will always make you a better dev.

--

--

Jason Warner
Jason Warner

Written by Jason Warner

I enjoy everything related to code and being a dev. However, my only skills are showing up and being lucky and I'm not sure if luck is a talent.

No responses yet