Mutable data types cause side effects, but what side effects specifically and how can they be grouped? So far I've found two sorts of effects:
- race conditions (due to single threaded JS in the context of asynchronous computations/event loop)
- erroneously expected idempotence
The first point is self-explanatory. However, the second one needs clarification:
const append = xs => ys =>
(xs.unshift(ys), xs);
const empty = [];
const fold = f => acc => ([x, ...xs]) =>
x === undefined
? acc
: f(fold(f) (acc) (xs)) (x);
const xs = [1,2,3];
const main = fold(append) (empty);
main(xs);
console.log(main(xs)); // [1,2,3,1,2,3]
The expected result is [1,2,3]
, but the operation is non-idempotent.
Are there any other sorts of side effects caused by mutable data types? Since such side effects cause so much trouble I think it important to know, which side effects you are likely to face.