On 23/03/14 10:23 AM, Bram Moolenaar wrote:
Ernie Rael wrote:

I sometimes want "collection->foreach((_, v) => ...v...)", a simple
one liner, no return or return ignored. I know it's not a performance
winner, or I'd want it more.

After a quick look at the code, it looks like simply introducing
another filtermap_T, FILTERMAP_FOREACH, and there's not much coding
needed (I only looked at list). Probably more work doing tests/doc.

Any objections or other considerations?
So, this would iterate over the items in a List or Dictionary and invoke
a function for each one.  I assume the List or Dictionary is not
modified, otherwise you would use map().
Yes, yes. Not modified as though `lockvar 1`, a structured value, like an inner list in a list of lists, could be modified.
Thus it's a short version of a
for loop.  This seems useful.

I would suggest first writing the help and think of any error conditions
that need to be handled.
The first PR will be doc only.
   Perhaps the collection should be locked
(frozen) to avoid trouble?

To protect against the script changing the list/dict top level structure during iteration? Aren't map/filter/mapnew susceptible to the script manipulating the source collection during iteration?

But it's always nice to get an exception if the script misbehaves. In this case, there can be no structure modification, unlike map/filter. I suppose with map/filter the list could be locked during the operation except when the return from the function indicates a change needs to be made (I've never looked at the lock code; have no idea of the overhead of an internal `lockvar 1`)

-ernie



--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/2b709080-3f01-a2d4-2202-56adc48208b7%40raelity.com.

Raspunde prin e-mail lui