Implies is a strong word... I'd say, "allows for". Per the ECMA standard, map() guarantees invocation order against the elements of the array, something that would be unnecessary to specify in a function that implies a pure function callback.
The standard itself explicitly says that while map doesn't mutate the object on which it is called, the callback function may mutate it (not just any old side effect here like console.log(), but a mutation of the object being called)... and there's an odd rule that if you delete an element from the array during the invocation of map(), but before map visits that element, that element will not be visited.
Sure, it's better style if it is pure, but the implication, if anything, is that it may be impure.
Lead Product Evangelist @Kentico, Founding partner @craftbrewingbiz. love to learn / teach web dev & software engineering, collecting vinyl records, mowing my lawn, craft 🍺
Implies is a strong word... I'd say, "allows for". Per the ECMA standard, map() guarantees invocation order against the elements of the array, something that would be unnecessary to specify in a function that implies a pure function callback.
The standard itself explicitly says that while map doesn't mutate the object on which it is called, the callback function may mutate it (not just any old side effect here like console.log(), but a mutation of the object being called)... and there's an odd rule that if you delete an element from the array during the invocation of map(), but before map visits that element, that element will not be visited.
Sure, it's better style if it is pure, but the implication, if anything, is that it may be impure.
Those are good points.
In much of the code I see,
map
andfilter
are used with pure functions.So, despite what the language allows, the use of them implies pure functions in my experience.
Following this pattern means you don't have to worry about the scenario you describe.