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
Documentation for maktaba#function#Filter says This is like |filter|, except {func} may be any maktaba callable and a new list is created. Unlike the builtin filter() function, {list} WILL NOT be modified in place.
The output from the following test indicates that it does modify the input.
lets:numbers= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
echo'starting list is's:numberslets:odds=maktaba#function#Filter(s:numbers, {x-> x%2==1})
echo'list with odds is's:oddslets:threes=maktaba#function#Filter(s:odds, {x-> x%3==0})
echo'list with threes is's:threesecho'now odds is's:oddsecho'now numbers is's:numbers
Output:
starting list is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list with odds is [1, 3, 5, 7, 9]
list with threes is [3, 9]
now odds is [3, 9]
now numbers is [3, 9]
The text was updated successfully, but these errors were encountered:
The docs could also clarify that it's unlike filter() in that func takes one arg, not two (builtin filter() passes v:key and v:val to functions. For example, filter(l:list, {x -> !empty(x)}) results in a list without its first element (whether or not the value was empty), but maktaba#function#filter(l:list, {x -> !empty(x)}) results in a list with no empty elements.
I didn't even notice that 2-arg difference. And also on that note, it only accepts lists where built-in filter() also accepts dictionaries. OTOH, it's a thin convenience wrapper around filter(copy(...), maktaba#function#Call(...)), so we probably don't need to bend over backwards to make it handle every case.
Documentation for
maktaba#function#Filter
saysThis is like |filter|, except {func} may be any maktaba callable and a new list is created. Unlike the builtin filter() function, {list} WILL NOT be modified in place.
The output from the following test indicates that it does modify the input.
Output:
The text was updated successfully, but these errors were encountered: