Open Nimelrian opened 7 years ago
Hello @Nimelrian. The documentation is clearly misleading because the describe operation should probably return NaN
indeed. The original intention was for apply to receive the value at the selected cursor to act upon, not to differentiate whether the value was an array or a scalar. But I admit the idea is interesting. However, I am not sure what this would mean if, say, the value at the cursor is a plain object.
If the value at the cursor would be a plain object, the behaviour would stay the same as it is right now. It passes the current object to the callback and replaces the cursor's value with the result. Basically Array.prototype.map
as if it were an array with a single object.
In code:
function apply (cursor, callback) {
const currentValue = cursor.get();
cursor.set(isArray(currentValue)
? currentValue.map(callback)
: callback(currentValue));
}
Hi,
I'm confused by the result of calling
apply
on a cursor pointing at a list. Looking at the documentation and the function's name, to me it would seem thatapply
works as follows:apply
-callback and replace the cursor's value with the result.Array.prototype.map
).This, however, does not seem to be the case, as visible in this short example:
Apparently it makes no distinction between the cursor value being an object or an array. Is this intended? In this case it would make sense to clarify this in the documentation, especially since it uses a variable called "newList" in the example: