Ernie Rael wrote:
> On 8/12/22 7:41 AM, Yegappan Lakshmanan wrote: > > Hi all, > > > > The index() function returns the lowest index in a List where an item > > has a value equal to the supplied expression. This function cannot be > > used to find an item with a specific key/value pair in a List of Dicts > > (or to use a custom search in a List). You need to resort to using a > > for loop to find the index. > > > > What do you think about extending the index() function to accept a > > lambda function (similar to map(), filter() and reduce())? This lambda > > function will be called with two arguments: the index of the item and the > > value of the item. If this function returns true, then the search will > > stop. > > > > Currently the index() function accepts four arguments (the first two > > arguments are mandatory and the last two arguments are optional). To > > support using a lambda function, a fifth optional argument 'eval' needs > > to be added. If this is true, then the second 'expr' argument will be > > evaluated. It would have been simpler to add new arguments if the third > > argument is a Dict. > > How about if the 3rd argument is a dict, then there are only/exactly > three arguments > and the dict specifies optional parameters? The old definition is > unchanged with 2+2. Instead making the index() arguments quite complicated, it's probably better to add a new function that takes two arguments: the list and a dict with various (optional) arguments. Or, to make it more like map() and filter(), the second argument would be the lambda/funcref and the third argument a dict with optional arguments. That's probably best, since the only optional argument that makes sense is the start index. Not sure what to call it, indexfunc() ? -- ARTHUR: Who are you? TALL KNIGHT: We are the Knights Who Say "Ni"! BEDEVERE: No! Not the Knights Who Say "Ni"! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20220812170549.128A11C0823%40moolenaar.net.