feat(array): only consider arg position, NOT defaultness or keywardness, when binding lambdas in Array.map() and Array.filter() #11116
+197
−148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have this util function:
which I want to be able to use as
my_table.filter(is_happy)
ormy_array_of_structs.filter(is_happy)
. Before this PR, this fails. Now, it works.This is a breaking change. Before, this worked:
my_array.map(functools.partial(lambda x, y, idx: x + y + idx, y=2))
. I don't think this should have ever worked, because this isn't a valid function to call with 2 positional arguments:Now, the user MUST supply a function that works as either
f(x)
orf(x, y)
(ie 1 or 2 positional arguments)This also makes it so that positional-only functions work. Before,
def f(x, /)
would fail. Now, it works.This also makes it so that
func(*args)
functions work. We call them asfunc(elem, idx)
.func(x, *args)
functions work. We call them asfunc(elem, idx)
.Basically, the way to explain this is fairly simple, and what I wrote in the docstrings: