You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 that apply works as follows:
If the cursor value is an object, pass that object to the apply-callback and replace the cursor's value with the result.
If the cursor value is a list / an array, iterate over the list, supplying each element to the callback. Collect the callback results in a new list and replace the original list with the new one (similar to 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:
varinc=function(nb){returnnb+1;};// Applying the functionvarnewList=cursor.apply(inc);
The text was updated successfully, but these errors were encountered:
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.
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:
The text was updated successfully, but these errors were encountered: