When nesting any block or control structures (if, for, while, switch, lambda), we should ask ourselves a few questions. Can we make this more readable? Does any part of this make sense on its own (i.e. refactor)? How could this code likely be changed in the future?
I wouldn’t religiously avoid nesting ifs like the plague, though we all should be able to identify a slippery slope and avoid maintenance nightmares. What’s more damaging than nesting ifs are those run-on blocks of logic (which usually use nesting) that scroll for days from start to finish. Of course, they never start out that way; a seemingly innocent choice can be patterned upon by its maintainers to the point of monstrosity.
I digress. Thanks for sharing. I tend to enjoy using maps instead of conditionals when it make sense.