Hey, couple thought. Im not sure switch statements are impure. They can be if you cause side effects, but so could any function.
I think in the case the switch is wrapped in a function and every case had a return statement inside it could be considered pure. This isn’t the typical usage I see switch statements used in. Though I think in some situations I would agree with you here.
Second nested ternary are evil
I like the nested ternary! Especially after discovering a format that makes the readable and intuitive. They follow a similar format to a switch when your
return are on the same line. They also follow a similar structure to Ramda’s
Lastly you could also replace switch with command or strategy pattern
The strategy pattern is an amazing pattern and I plan on writing another article based off of this pattern. I didn’t use it here because I thought it would have complicated the article up a bit much.