Caching side-effects
By detecting that no changes have been made in a collection, you can skip the side-effect that would otherwise iterate over the collection, possibly running transformations along the way. Essentially, you're caching the side-effect. Usually, when you cache functions, you cache a value that's returned by the function. Side-effects are different because they effect the external environment in some way. For example, a UI component that uses an Immutable.js collection has been rendered. You then ask the component to render itself again, even though the collection that it uses hasn't changed at all. This side-effect can simply be ignored since it's already represented by the UI.
Let's build a generic mechanism that can be used to cache arbitrary side-effect functions:
const sideEffectCache = new WeakMap();
const sideEffect = fn => (...args) => {
const cache = sideEffectCache.get(fn)
|| new Array(args.length);
const miss = Seq(args)
.zip(cache)
.some(([a...