Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP/ALL/ANY are replacing missing item value with previous item value #232

Closed
vlazar opened this issue Feb 3, 2021 · 2 comments
Closed

Comments

@vlazar
Copy link
Contributor

vlazar commented Feb 3, 2021

c = Dentaku::Calculator.new

# correct
c.evaluate!("MAP(items, i, i.value)", items: [{value: 1}, {value: nil}, {value: 2}, {value: nil}])
#  => [1, nil, 2, nil]

# bug
c.evaluate!("MAP(items, i, i.value)", items: [{value: 1}, {}, {value: 2}, {}])
# => [1, 1, 2, 2]

MAPP/ALL/ANY share a very similar implementation, so ALL and ANY have the same issue of keeping a value from previous item if current item value is missing.

@rubysolo
Copy link
Owner

rubysolo commented Mar 4, 2021

The context mutation bug is fixed in d77dd3b; however, it might not work as you want, because any item that does not have the key you're looking for will raise an unbound variable error.

@vlazar
Copy link
Contributor Author

vlazar commented Mar 24, 2021

@rubysolo Thank you for the fix!

The behavior makes more sense now. However as you pointed out it will now raise an unbound variable error on missing keys. I've been thinking about this distinction for quite a while now.

I think that in general I need a way to be able chose between a more strict behavior (the one with fix) and an old one where the outcome would be nil in result instead of unbound variable exception.

I've opened a separate issue to discuss it: #236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants