Mmm I can't help pointing out that these aren't pure functions. A pure function takes a set of parameters and produces the same result every time for the same set of parameters, without performing any side effects. Just because a function does something vaguely analogous to the "map" concept that is generally used as a pure function example does not mean that it is a pure function.
Also, to use your "map" example again -- that isn't actually even analogous to map. Much closer:
const middleware = (store) => (next) => (action) => {
if (action.type === 'ACTION_FROM') {
// We want to map this to a different action
next({ ...action, type: 'ACTION_TO' })
}
else
{
next(action);
}
}
Mmm I can't help pointing out that these aren't pure functions. A pure function takes a set of parameters and produces the same result every time for the same set of parameters, without performing any side effects. Just because a function does something vaguely analogous to the "map" concept that is generally used as a pure function example does not mean that it is a pure function.
Also, to use your "map" example again -- that isn't actually even analogous to map. Much closer:
Hi @johnkievlan , thanks for your feedback!
Well, you're right, these aren't pure functions for real.
This post is intended to be a point of view and a source of inspiration, not an over-engineered one.
And thanks for the better example, it may be useful for further readers!