> In practice, it's very difficult (in most languages) to determine whether this optimisation is correct.
>
> [...] the optimisation happens to be correct because both mapping functions are pure. If they had side effects, [...]
TLDR: make all your functions pure. It'll make it so much simpler for you, your coworkers, but also the compiler(!) to reason about your code.
About half of the bugs and issues I come across in my $DAYJOB are because code that I use (through a third-party library) is not pure. If I had a penny every time I fixed a bug caused by impure code, I'd be rich.
TLDR: make all your functions pure. It'll make it so much simpler for you, your coworkers, but also the compiler(!) to reason about your code.
About half of the bugs and issues I come across in my $DAYJOB are because code that I use (through a third-party library) is not pure. If I had a penny every time I fixed a bug caused by impure code, I'd be rich.